Huge News!Announcing our $40M Series B led by Abstract Ventures.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.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]]]
```
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