arr-flatten
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -1,4 +0,1 @@ | ||
--- | ||
tags: ['verb-tag-jscomments'] | ||
--- | ||
# {%= name %} {%= badge("fury") %} | ||
@@ -8,5 +5,10 @@ | ||
## Install | ||
{%= include("install") %} | ||
Why another flatten utility? Because this one is faster. | ||
## Run benchmarks | ||
```bash | ||
node benchmark | ||
``` | ||
## Run tests | ||
@@ -18,13 +20,16 @@ | ||
## Install | ||
{%= include("install-npm", {save: true}) %} | ||
{%= include("install-bower", {save: true}) %} | ||
## Usage | ||
```js | ||
var arrayFlatten = require('{%= name %}'); | ||
console.log(arrayFlatten('abc')); | ||
//=> ['a', 'b', 'c']; | ||
var flatten = require('{%= name %}'); | ||
flatten(['a', ['b', ['c']], 'd', ['e']]); | ||
//=> ['a', 'b', 'c', 'd', 'e'] | ||
``` | ||
## API | ||
{%= jscomments("index.js") %} | ||
## Author | ||
@@ -31,0 +36,0 @@ {%= include("author") %} |
24
index.js
@@ -10,10 +10,20 @@ /*! | ||
module.exports = function () { | ||
var args = [].slice.call(arguments); | ||
module.exports = function (arr) { | ||
return flatten(arr, []); | ||
}; | ||
do { | ||
args = [].concat.apply([], args); | ||
} while (args.some(Array.isArray)); | ||
function flatten(arr, res) { | ||
var len = arr.length; | ||
var num = 0; | ||
return args; | ||
}; | ||
while (len--) { | ||
var i = num++; | ||
if (Array.isArray(arr[i])) { | ||
flatten(arr[i], res); | ||
} else { | ||
res.push(arr[i]); | ||
} | ||
} | ||
return res; | ||
} |
{ | ||
"name": "arr-flatten", | ||
"description": "Recursively flatten an array or arrays.", | ||
"version": "0.1.0", | ||
"description": "Recursively flatten an array or arrays. This is the fastest implementation of array flatten.", | ||
"version": "0.2.0", | ||
"homepage": "https://github.com/jonschlinkert/arr-flatten", | ||
@@ -31,2 +31,8 @@ "author": { | ||
"devDependencies": { | ||
"array-flatten": "^1.0.0", | ||
"array-slice": "^0.2.2", | ||
"benchmarked": "^0.1.3", | ||
"chalk": "^0.5.1", | ||
"glob": "^4.0.6", | ||
"kind-of": "^0.1.2", | ||
"mocha": "*", | ||
@@ -51,2 +57,2 @@ "should": "^4.0.4", | ||
] | ||
} | ||
} |
@@ -14,5 +14,9 @@ /*! | ||
describe('flatten', function () { | ||
it('should array flatten', function () { | ||
flatten(['a', ['b', ['c']]], ['d', ['e']]).should.eql(['a', 'b', 'c', 'd', 'e']); | ||
it('should flatten nested arrays:', function () { | ||
flatten(['a', 'b', ['c'], 'd', ['e']]).should.eql(['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']); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
10107
24
193
0
55
10
2