Flatten a Nested Array of Arbitrary Depth #722
Replies: 1 comment
a utility to flatten nested arrays of arbitrary depth without using .flat(), while also preserving sparseness (holes stay holes). js
const result = []; while (stack.length) { } // Convert placeholders that came from holes into actual holes. function flattenSparseWithHoleTracking(input) { const stack = [{ arr: input, idx: 0 }]; while (stack.length) { } // Turn placeholders into actual holes. return result; |
Uh oh!
There was an error while loading. Please reload this page.
Flatten a Nested Array of Arbitrary Depth
Do it without using .flat(), and handle sparse arrays.
All reactions