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() { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
4084
2
115
40