loading...

Intermediate Algorithm Scripting: Steamroller FCC

95freedom95 profile image Oscar Hernandez ・1 min read

/Intermediate Algorithm Scripting: Steamroller
Flatten a nested array. You must account for varying levels of nesting.
/
function steamrollArray(arr) {
var x = arr.reduce((acc, val) => Array.isArray(val) ? acc.concat(steamrollArray(val)) : acc.concat(val), []);
console.log(x)
return x
}
steamrollArray([1, [2], [3, [[4]]]]);
steamrollArray([[["a"]], [["b"]]]);
steamrollArray([1, [], [3, [[4]]]]);
steamrollArray([1, {}, [3, [[4]]]])
/https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/steamroller/
/https://developer.mozilla.org/es/docs/Web/JavaScript/Referencia/Objetos_globales/Array/flat/

Discussion

markdown guide