1 2 3 4 5 6 7
function interleave(stack) { for (let queue = [], len = stack.length, i = 1; i < len; ++i) { while (stack.length > i) queue.push(stack.pop()) while (queue.length > 0) stack.push(queue.shift()) } return stack }
You can clone a snippet to your computer for local editing. Learn more.