Files
30-seconds-of-code/snippets/isPowerOfTen.md
Isabelle Viktoria Maciohsek 8bf67754ce Make expertise a field
2022-03-01 20:21:45 +02:00

436 B

title, tags, expertise, firstSeen, lastUpdated
title tags expertise firstSeen lastUpdated
Number is power of ten math beginner 2021-01-06T22:53:58+02:00 2021-01-06T22:53:58+02:00

Checks if the given number is a power of 10.

  • Use 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