Find Nth Magic Number Leetcode Javascript