Nth Magical Number Leetcode Javascript Solution