Add isPowerOfTen

This commit is contained in:
Chalarangelo
2021-01-06 22:53:58 +02:00
parent f18f61f5b2
commit f676138ab3

18
snippets/isPowerOfTen.md Normal file
View File

@ -0,0 +1,18 @@
---
title: isPowerOfTen
tags: math,beginner
---
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
```