Functional Javascript Rubik's cube