just-flatten-it
Advanced tools
Comparing version 2.2.0 to 2.2.1
26
index.js
@@ -8,11 +8,12 @@ module.exports = flatten; | ||
function flattenHelper(arr, depth) { | ||
function flatten(arr) { | ||
if (!Array.isArray(arr)) { | ||
throw new Error('expected an array'); | ||
} | ||
var result = []; | ||
var len = arr.length; | ||
for (var i = 0; i < len; i++) { | ||
var elem = arr[i]; | ||
if (Array.isArray(elem) && depth > 0) { | ||
result.push.apply(result, flattenHelper(elem, depth - 1)); | ||
if (Array.isArray(elem)) { | ||
result.push.apply(result, flatten(elem)); | ||
} else { | ||
@@ -22,18 +23,3 @@ result.push(elem); | ||
} | ||
return result; | ||
} | ||
function flatten(arr, depth) { | ||
if (!Array.isArray(arr)) { | ||
throw new Error('expected an array'); | ||
} | ||
if (depth !== undefined && typeof depth !== 'number') { | ||
throw new Error('depth expects a number'); | ||
} | ||
var optionDepth = typeof depth === 'number' ? depth : Infinity; | ||
return flattenHelper(arr, optionDepth); | ||
} |
{ | ||
"name": "just-flatten-it", | ||
"version": "2.2.0", | ||
"version": "2.2.1", | ||
"description": "return a flattened array", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -13,5 +13,2 @@ ## just-flatten-it | ||
// [1, 2, 3, 4, 5, 6, 7, 8, 9] | ||
flatten([[1, [2, 3]], [[4, 5], 6, 7, [8, 9]]], 1); | ||
// [1, [2, 3], [[4, 5], 6, 7, [8, 9]]] | ||
``` |
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
2345
21
14