Beat the Codility Coding Interview in JavaScript