Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

longest

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

longest - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

24

index.js
/**
* Longest
* longest item in an array
* Copyright (c) 2014 Jon Schlinkert, contributors.

@@ -9,9 +9,17 @@ * Licensed under the MIT license.

module.exports = function (arr) {
function compare(a, b) {
if (a.length > b.length) {return -1;}
if (a.length < b.length) {return 1;}
return 0;
};
return arr.sort(compare)[0];
module.exports = function(arr) {
var c = 0,
len = 0,
l = 0,
idx = arr.length;
if (idx) {
while (idx--) {
len = arr[idx].length;
if (len > c) {
l = idx;
c = len;
}
}
}
return arr[l];
};
{
"name": "longest",
"version": "0.1.0",
"version": "0.2.0",
"description": "Get the length of the longest item in an array.",

@@ -24,5 +24,4 @@ "main": "index.js",

"mocha": "~1.17.0",
"chai": "~1.8.1",
"fs-utils": "~0.1.4"
"chai": "~1.8.1"
}
}

@@ -18,2 +18,15 @@ # longest

## Usage
```js
var longest = require('longest');
var arr = ['a', 'bb', 'ccc'];
console.log(longest(arr));
//=> ccc
console.log(longest(arr).length);
//=> 3
```
## Author

@@ -27,3 +40,3 @@

## License
Copyright (c) 2014 Jon Schlinkert, Brian Woodward, contributors.
Copyright (c) 2014 Jon Schlinkert, contributors.
Released under the MIT license
/**
* Longest
* logest item in an array
* Copyright (c) 2014 Jon Schlinkert <https://github.com/jonschlinkert>

@@ -8,11 +8,7 @@ * Licensed under the MIT License (MIT).

// node_modules
var file = require('fs-utils');
var fs = require('fs');
var expect = require('chai').expect;
// Local lib
var longest = require('../');
var arr = JSON.parse(fs.readFileSync('test/fixtures/arr.json').toString());
var fixtures = require('path').join.bind(null, __dirname, 'fixtures');
var arr = file.readJSONSync(fixtures('arr.json'));
// Tests

@@ -19,0 +15,0 @@ describe('longest', function() {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc