Tell us what’s happening:
Here’s my solution and it does work (for all the cases as given on FreeCodeCamp for this challenge), but when I run to test it, it doesn’t pass. I’ve tried all the following cases, and it does return the right values, but none of the tests pass when I run test on FreeCodeCamp.
steamrollArray([[[“a”]], [[“b”]]]) should return [“a”, “b”].
steamrollArray([1, [2], [3, [[4]]]]) should return [1, 2, 3, 4].
steamrollArray([1, , [3, [[4]]]]) should return [1, 3, 4].
steamrollArray([1, {}, [3, [[4]]]]) should return [1, {}, 3, 4].
Your code so far
let vals = [];
function steamrollArray(arr) {
arr.forEach((val) => {
if (Array.isArray(val)){
steamrollArray(val);
} else {
vals.push(val);
}
});
return vals;
}
steamrollArray([[["a"]], [["b"]]]);
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.86
.
Link to the challenge:
https://www.freecodecamp.org/challenges/steamroller