Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Recursive/FlattenedArray.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

// https://flexiple.com/flatten-array-javascript/
// Flatten an given array to reduce the dimensionality of an array

const flattened = (arr) => {
const res = []
arr.forEach(i => {
if(Array.isArray(i)){
res.push(...flattened(i));
}
else{
res.push(i);
}
});
return res;
}

module.exports = flattened;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
module.exports = flattened;
export { flattened }

Use ESM