Added implementation that isn't quite as efficient as possible answer
More efficient solution
Playing with apply, call, bind

JS version of the switchArrayInPlace
js version of the queue with two stacks funsies

Slight refractor of the ruby version as well