Files
30-seconds-of-code/snippets/is-power-of-ten.md
Angelos Chalaris 61200d90c4 Kebab file names
2023-04-27 21:58:35 +03:00

458 B

title, tags, author, cover, firstSeen, lastUpdated
title tags author cover firstSeen lastUpdated
Number is power of ten math chalarangelo boulder-beach 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