Meta Interview Question

Write an array flatten function.

Interview Answers

Anonymous

Jan 25, 2018

let flat = (z = []) => { return !Array.isArray(z) ? [].concat(z) : (z.length > 0) ? flat(z.splice(0, 1)[0]).concat(flat(z)) : z }

Anonymous

Jan 27, 2018

I have an O(n) solution for this ;)