flatten-array
Advanced tools
Comparing version 0.0.1 to 0.0.2
20
index.js
module.exports = flatten; | ||
function flatten(list){ | ||
var result; | ||
function flatten (list, result) { | ||
if(!Array.isArray(list)) return list; | ||
result = []; | ||
var i = -1; | ||
var len = list.length; | ||
list.forEach(function(el){ | ||
result || (result = []); | ||
if(!Array.isArray(el)) { | ||
return result.push(el); | ||
while (++i < len) { | ||
if (!Array.isArray(list[i])) { | ||
result.push(list[i]); | ||
continue; | ||
} | ||
result.push.apply(result, flatten(el)); | ||
flatten(list[i], result); | ||
} | ||
}); | ||
return result; | ||
} |
{ | ||
"name": "flatten-array", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Flattens nested arrays.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -17,3 +17,4 @@ ## flatten-array | ||
flatten([1, 2, [3, [4, 5], 6], 7]) | ||
// => [1, 2, 3, 4, 5, 6, 7] | ||
// => [1, 2, 3, 4, 5, 6, 7] | ||
``` |
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
945
15
20