Nth Magical Number Leetcode Javascript Question