Also, for testing purposes, can I suggest to store the resul of your method in a variable and then both console.log it and return it? In this way you don’t have to pieces of code to update. Later you can remove the extra variable declaration and return that value directly and chain the various methods, once you get the desired output.
Yes, thanks for the input. I’ve solved this challenge now, but you are correct it’s a bit messy to repeat the lines inside the console.log() and the return statement. I could’ve tidied that up a bit before posting here sorry.
After Kevin’s first response above, I re-read my own code and understood what was going on. The solution I ended up with was much neater. I’d paste it in here but I’m not sure how to mark as a spoiler (if that’s possible).
It leads me to ask one question relating to array spread syntax though. Often instead of .concat() I will use something like [ …arr, newItem] but it seems this can’t be done when newItem is a function call? Something like […arr, steamrollArray(item)]. Is that correct?
It depends on how steamrollArray() is made - if you use recursion you need your function to have a condition for which recursion doesn’t happen, or the function will call itself infinitely
To post a spoiler you can hide it using [spoiler][/spoiler] tags