Comparing version 0.2.1 to 0.3.0
{ | ||
"name": "longest", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"main": [ | ||
"index.js" | ||
], | ||
"authors": [ | ||
{ | ||
"name": "Jon Schlinkert", | ||
"homepage": "https://github.com/jonschlinkert" | ||
} | ||
] | ||
} |
41
index.js
/** | ||
* longest item in an array | ||
* Copyright (c) 2014 Jon Schlinkert, contributors. | ||
* longest <https://github.com/jonschlinkert/longest> | ||
* | ||
* Copyright (c) 2014 Jon Schlinkert | ||
* Licensed under the MIT license. | ||
@@ -10,16 +11,28 @@ */ | ||
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; | ||
} | ||
if (!arr) { | ||
return null; | ||
} | ||
var len = arr.length; | ||
if (!len) { | ||
return null; | ||
} | ||
var c = 0; | ||
var i = 0; | ||
var ele; | ||
var elen; | ||
var res; | ||
for (; i < len; i++) { | ||
ele = arr[i]; | ||
elen = ele.length; | ||
if (elen > c) { | ||
res = ele; | ||
c = elen; | ||
} | ||
} | ||
return arr[l]; | ||
return res; | ||
}; |
{ | ||
"name": "longest", | ||
"version": "0.2.1", | ||
"description": "Get the length of the longest item in an array.", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "mocha" | ||
"version": "0.3.0", | ||
"description": "Get the longest item in an array.", | ||
"homepage": "https://github.com/jonschlinkert/longest", | ||
"author": { | ||
"name": "Jon Schlinkert", | ||
"url": "https://github.com/jonschlinkert" | ||
}, | ||
@@ -16,12 +17,29 @@ "repository": { | ||
}, | ||
"licenses": [ | ||
{ | ||
"type": "MIT", | ||
"url": "https://github.com/jonschlinkert/longest/blob/master/LICENSE-MIT" | ||
} | ||
], | ||
"license": { | ||
"type": "MIT", | ||
"url": "https://github.com/jonschlinkert/longest/blob/master/LICENSE-MIT" | ||
}, | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "mocha" | ||
}, | ||
"engines": { | ||
"node": ">=0.10.0" | ||
}, | ||
"devDependencies": { | ||
"mocha": "~1.17.0", | ||
"chai": "~1.8.1" | ||
} | ||
"fill-range": "^0.2.0", | ||
"mocha": "*", | ||
"should": "^4.3.0" | ||
}, | ||
"keywords": [ | ||
"array", | ||
"element", | ||
"item", | ||
"javascript", | ||
"long", | ||
"longest", | ||
"util", | ||
"utility", | ||
"utils" | ||
] | ||
} |
@@ -1,14 +0,12 @@ | ||
# longest | ||
# longest [![NPM version](https://badge.fury.io/js/longest.svg)](http://badge.fury.io/js/longest) | ||
> Get the length of the longest item in an array. | ||
> Get the longest item in an array. | ||
## Install with [npm](npmjs.org) | ||
Install with [npm](npmjs.org) | ||
```bash | ||
npm i longest --save | ||
``` | ||
### Install with [bower](https://github.com/bower/bower) | ||
Install with [bower](https://github.com/bower/bower) | ||
```bash | ||
@@ -18,2 +16,8 @@ bower install longest --save | ||
## Run tests | ||
```bash | ||
npm test | ||
``` | ||
## Usage | ||
@@ -23,10 +27,11 @@ | ||
var longest = require('longest'); | ||
var arr = ['a', 'bb', 'ccc']; | ||
console.log(longest(arr)); | ||
//=> ccc | ||
longest(['a', 'abcde', 'abc']); | ||
//=> 'abcde' | ||
console.log(longest(arr).length); | ||
//=> 3 | ||
longest(['a', 'abcde', 'abc']).length; | ||
//=> 5 | ||
``` | ||
## Contributing | ||
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/longest/issues) | ||
@@ -36,8 +41,12 @@ ## Author | ||
**Jon Schlinkert** | ||
+ [github/jonschlinkert](https://github.com/jonschlinkert) | ||
+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert) | ||
+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert) | ||
## License | ||
Copyright (c) 2014 Jon Schlinkert, contributors. | ||
Released under the MIT license | ||
Copyright (c) 2014 Jon Schlinkert | ||
Released under the MIT license | ||
*** | ||
_This file was generated by [verb](https://github.com/assemble/verb) on November 28, 2014._ |
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
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
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
5437
10
1
1
49
0
3
58