DEV Community

Oscar Hernandez
Oscar Hernandez

Posted on

2

Intermediate Algorithm Scripting: Steamroller FCC

/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/

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay