Q-Learning Algorithm in JavaScript