Files
30-seconds-of-code/snippets/isPowerOfTen.md
Angelos Chalaris 8a6b73bd0c Update covers
2023-02-16 22:24:28 +02:00

23 lines
458 B
Markdown

---
title: Number is power of ten
tags: math
author: chalarangelo
cover: boulder-beach
firstSeen: 2021-01-06T22:53:58+02:00
lastUpdated: 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`.
```js
const isPowerOfTen = n => Math.log10(n) % 1 === 0;
```
```js
isPowerOfTen(1); // true
isPowerOfTen(10); // true
isPowerOfTen(20); // false
```