1
var isUgly = function (n) {
2
let condition = true;
3
if (n == 0)
4
// 0 has infinite factors. So checking if the number is 0 or not
5
return false;
6
while (condition) {
7
//applying for true until 2, 3, 5 gets removed from the number
8
if (n % 2 == 0) n = n / 2;
9
else if (n % 3 == 0) n = n / 3;
10
else if (n % 5 == 0) n = n / 5;
11
else condition = false; //if the number doesnt have 2, 3, 5 in it anymore, this part will execute and will end the while loop
12
}
13
return n == 1 ? true : false; //checking if the number only had 2, 3, 5 in it or had something else in it as well
14
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0