New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

just-flatten-it

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

just-flatten-it - npm Package Compare versions

Comparing version 2.1.0 to 2.2.0

26

index.js

@@ -8,12 +8,11 @@ module.exports = flatten;

function flatten(arr) {
if (!Array.isArray(arr)) {
throw new Error('expected an array');
}
function flattenHelper(arr, depth) {
var result = [];
var len = arr.length;
for (var i = 0; i < len; i++) {
var elem = arr[i];
if (Array.isArray(elem)) {
result.push.apply(result, flatten(elem));
if (Array.isArray(elem) && depth > 0) {
result.push.apply(result, flattenHelper(elem, depth - 1));
} else {

@@ -23,3 +22,18 @@ 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.1.0",
"version": "2.2.0",
"description": "return a flattened array",

@@ -21,2 +21,2 @@ "main": "index.js",

}
}
}

@@ -13,2 +13,5 @@ ## 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]]]
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc