Genesys interview question

Write a flatten function, given a (possibly) multi-dimensional array as a parameter.

Interview Answer

Anonymous

Feb 21, 2020

I used tail recursion, passing in the orginal array and an accumulator array. On every call, I would add the head to the accumulator array if it was not an array, and recursively call the function if the head was an array. I would remove the head on every recursive call, until the original array had no more elements, then I returned the accumulator array.