just-flatten-it
Advanced tools
Comparing version 3.0.0 to 3.1.0
19
index.js
@@ -9,16 +9,17 @@ module.exports = flatten; | ||
function flattenHelper(arr, depth) { | ||
var stack = arr.slice(); | ||
var result = []; | ||
var len = arr.length; | ||
for (var i = 0; i < len; i++) { | ||
var elem = arr[i]; | ||
while (stack.length) { | ||
var item = stack.pop(); | ||
if (Array.isArray(elem) && depth > 0) { | ||
result.push.apply(result, flattenHelper(elem, depth - 1)); | ||
if (Array.isArray(item) && depth > 0) { | ||
stack.push.apply(stack, item); | ||
depth--; | ||
} else { | ||
result.push(elem); | ||
result.push(item); | ||
} | ||
} | ||
return result; | ||
return result.reverse(); | ||
} | ||
@@ -35,5 +36,3 @@ | ||
var optionDepth = typeof depth === 'number' ? depth : Infinity; | ||
return flattenHelper(arr, optionDepth); | ||
return flattenHelper(arr, typeof depth === 'number' ? depth : Infinity); | ||
} |
{ | ||
"name": "just-flatten-it", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"description": "return a flattened array", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
2698