Tell us what’s happening:
Based on the output of each test, I have passed this challenge. However, I continue to fail all tests except for the one regarding using the .flat() and .flatmap() methods. I’m also failing the test for using global variables.
I need some help about why this is happening. I’m wondering if the second argument to the reduce function (“[ ]”) is perhaps triggering the global variable check? Let me know your thoughts! Thanks!
Your code so far
function flatten(arr) {
return arr.reduce((previous, current) => {
if (Array.isArray(current)) {
return [...previous, ...flatten(current)]
} else {
return [...previous, current]
}
}, [])
}
flatten([1, [], [3, [[4]]]])
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36
Challenge: Intermediate Algorithm Scripting - Steamroller
Link to the challenge: