arr-flatten
Advanced tools
Comparing version 0.2.1 to 1.0.0
15
index.js
/*! | ||
* arr-flatten <https://github.com/jonschlinkert/arr-flatten> | ||
* | ||
* Copyright (c) 2014 Jon Schlinkert, contributors. | ||
* Copyright (c) 2014-2015, Jon Schlinkert. | ||
* Licensed under the MIT License | ||
@@ -16,14 +16,13 @@ */ | ||
var len = arr.length; | ||
var num = 0; | ||
var i = -1; | ||
while (len--) { | ||
var i = num++; | ||
if (Array.isArray(arr[i])) { | ||
flat(arr[i], res); | ||
var cur = arr[++i]; | ||
if (Array.isArray(cur)) { | ||
flat(cur, res); | ||
} else { | ||
res.push(arr[i]); | ||
res.push(cur); | ||
} | ||
} | ||
return res; | ||
} | ||
} |
{ | ||
"name": "arr-flatten", | ||
"description": "Recursively flatten an array or arrays. This is the fastest implementation of array flatten.", | ||
"version": "0.2.1", | ||
"version": "1.0.0", | ||
"homepage": "https://github.com/jonschlinkert/arr-flatten", | ||
@@ -17,8 +17,6 @@ "author": { | ||
}, | ||
"licenses": [ | ||
{ | ||
"type": "MIT", | ||
"url": "https://github.com/jonschlinkert/arr-flatten/blob/master/LICENSE-MIT" | ||
} | ||
], | ||
"license": { | ||
"type": "MIT", | ||
"url": "https://github.com/jonschlinkert/arr-flatten/blob/master/LICENSE" | ||
}, | ||
"main": "index.js", | ||
@@ -29,30 +27,24 @@ "engines": { | ||
"scripts": { | ||
"test": "mocha -R spec" | ||
"test": "mocha -R spec", | ||
"benchmarks": "node benchmark" | ||
}, | ||
"devDependencies": { | ||
"array-flatten": "^1.0.0", | ||
"array-flatten": "^1.0.2", | ||
"array-slice": "^0.2.2", | ||
"benchmarked": "^0.1.3", | ||
"chalk": "^0.5.1", | ||
"glob": "^4.0.6", | ||
"kind-of": "^0.1.2", | ||
"mocha": "*", | ||
"should": "^4.0.4", | ||
"verb": ">= 0.2.6", | ||
"verb-tag-jscomments": ">= 0.2.0" | ||
"glob": "^4.3.5", | ||
"kind-of": "^1.0.0" | ||
}, | ||
"keywords": [ | ||
"recurse", | ||
"recursive", | ||
"recursively", | ||
"arr", | ||
"array", | ||
"util", | ||
"utils", | ||
"utility", | ||
"javascript", | ||
"node.js", | ||
"elements", | ||
"flat", | ||
"flatten" | ||
"flatten", | ||
"nested", | ||
"recurse", | ||
"recursive", | ||
"recursively" | ||
] | ||
} |
@@ -5,3 +5,3 @@ # arr-flatten [![NPM version](https://badge.fury.io/js/arr-flatten.svg)](http://badge.fury.io/js/arr-flatten) | ||
Why another flatten utility? Because this one is faster. | ||
Why another flatten utility? I wanted the fastest implementation I could find, with implementation choices that should work for 95% of use cases, but no cruft to cover the other 5%. | ||
@@ -11,13 +11,31 @@ ## Run benchmarks | ||
```bash | ||
node benchmark | ||
npm run benchmarks | ||
``` | ||
Benchmark results comparing this library to [array-flatten]: | ||
```bash | ||
#1: large.js | ||
arr-flatten.js x 487,030 ops/sec ±0.67% (92 runs sampled) | ||
array-flatten.js x 347,020 ops/sec ±0.57% (98 runs sampled) | ||
#2: medium.js | ||
arr-flatten.js x 1,914,516 ops/sec ±0.76% (94 runs sampled) | ||
array-flatten.js x 1,391,661 ops/sec ±0.63% (96 runs sampled) | ||
#3: small.js | ||
arr-flatten.js x 5,158,980 ops/sec ±0.85% (94 runs sampled) | ||
array-flatten.js x 3,683,173 ops/sec ±0.79% (97 runs sampled) | ||
``` | ||
## Run tests | ||
Install dev dependencies: | ||
```bash | ||
npm test | ||
npm i -d && npm test | ||
``` | ||
## Install | ||
#### Install with [npm](npmjs.org) | ||
## Install with [npm](npmjs.org) | ||
@@ -27,3 +45,3 @@ ```bash | ||
``` | ||
#### Install with [bower](https://github.com/bower/bower) | ||
### Install with [bower](https://github.com/bower/bower) | ||
@@ -52,3 +70,3 @@ ```bash | ||
## License | ||
Copyright (c) 2014 Jon Schlinkert, contributors. | ||
Copyright (c) 2015 Jon Schlinkert | ||
Released under the MIT license | ||
@@ -58,2 +76,4 @@ | ||
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on November 09, 2014._ | ||
_This file was generated by [verb](https://github.com/assemble/verb) on January 19, 2015._ | ||
[array-flatten]: https://github.com/blakeembrey/array-flatten |
14
test.js
/*! | ||
* arr-flatten <https://github.com/jonschlinkert/arr-flatten> | ||
* | ||
* Copyright (c) 2014 Jon Schlinkert, contributors. | ||
* Copyright (c) 2014-2015, Jon Schlinkert. | ||
* Licensed under the MIT License | ||
@@ -10,13 +10,17 @@ */ | ||
var should = require('should'); | ||
var assert = require('assert'); | ||
var flatten = require('./'); | ||
var arrFlatten = require('array-flatten'); | ||
describe('flatten', function () { | ||
it('should flatten nested arrays:', function () { | ||
flatten(['a', 'b', ['c'], 'd', ['e']]).should.eql(['a', 'b', 'c', 'd', 'e']); | ||
assert.deepEqual(flatten(['a', 'b', ['c'], 'd', ['e']]), ['a', 'b', 'c', 'd', 'e']); | ||
}); | ||
it('should flatten deeply nested arrays:', function () { | ||
flatten(['a', [[[[[[[['b', [['c']]]]]], 'd', ['e']]]]]]).should.eql(['a', 'b', 'c', 'd', 'e']); | ||
assert.deepEqual(flatten(['a', [[[[[[[['b', [['c']]]]]], 'd', ['e']]]]]]), ['a', 'b', 'c', 'd', 'e']); | ||
assert.deepEqual(flatten(['a', 'b', ['c'], 'd', ['e']]), ['a', 'b', 'c', 'd', 'e']); | ||
assert.deepEqual(flatten([['a', ['b', ['k', ['a', ['b', ['c'], [['a', [['a', ['b', ['k', ['a', ['b', ['c']], ['a', ['x', ['c'], ['a', ['x', ['k']]], ['d', ['z']]]], ['d', ['m']]], ['d', ['e']]]]], ['d', ['e']]], ['b', ['k', ['a', ['b', ['c']], ['a', ['x', ['c'], ['a', ['x', ['k']]], ['d', ['z']]]], ['d', ['m']]], ['d', ['e']]]]], ['d', ['e']]]], ['a', ['x', ['c'], ['a', ['x', ['k']], [['a', ['b', ['k', ['a', ['b', ['c']], ['a', ['x', ['c'], ['a', ['x', ['k']]], ['d', ['z']]]], ['d', ['m']]], ['d', ['e']]]]], ['d', ['e']]]], ['d', ['z']]]], ['d', ['m']]], ['d', ['e']]]]], ['d', ['e']]]), [ 'a', 'b', 'k', 'a', 'b', 'c', 'a', 'a', 'b', 'k', 'a', 'b', 'c', 'a', 'x', 'c', 'a', 'x', 'k', 'd', 'z', 'd', 'm', 'd', 'e', 'd', 'e', 'b', 'k', 'a', 'b', 'c', 'a', 'x', 'c', 'a', 'x', 'k', 'd', 'z', 'd', 'm', 'd', 'e', 'd', 'e', 'a', 'x', 'c', 'a', 'x', 'k', 'a', 'b', 'k', 'a', 'b', 'c', 'a', 'x', 'c', 'a', 'x', 'k', 'd', 'z', 'd', 'm', 'd', 'e', 'd', 'e', 'd', 'z', 'd', 'm', 'd', 'e', 'd', 'e' ]); | ||
}); | ||
}); | ||
}); | ||
Nonpermissive License
License(Experimental) A package's licensing information has fine-grained problems
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
8576
6
51
0
74
1