Number Following A Pattern Leetcode Javascript Problems