10
.Math.log10()
and the modulo operator (%
) to determine if n
is a power of 10
.const isPowerOfTen = n => Math.log10(n) % 1 === 0;
isPowerOfTen(1); // true
isPowerOfTen(10); // true
isPowerOfTen(20); // false
Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️