code.ashish.me

Atom feed

Recently added: 128 Longest Consecutive Sequence, 347 Top K Frequent Elements, 045 Jump Game 2, 228 Summary Ranges, 219 Contains Duplicate 2

263 Ugly Number

/**
 *
 * Ashish Patel
 * e: ashishsushilPatel@gmail.com
 * w: https://ashish.me
 *
 */

const uglyNumber = n => {
  if (n <= 0) {
    return false
  }
  const nums = [2, 3, 5]
  for (let i = 0; i < nums.length; i++) {
    while (n % nums[i] == 0) {
      n = Math.floor(n / nums[i])
    }
  }
  return n == 1
}

console.log(uglyNumber(6))

Created 2022-03-20T09:29:13+00:00 · Edit