Machine Learning Interview Leetcode Javascript Solution