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

21 lines
426 B
Markdown

---
title: Logarithm in specific base
tags: math
expertise: beginner
firstSeen: 2020-10-07T19:14:30+03:00
lastUpdated: 2020-10-22T20:23:47+03:00
---
Calculates the logarithm of the given number in the given base.
- Use `Math.log()` to get the logarithm from the value and the base and divide them.
```js
const logBase = (n, base) => Math.log(n) / Math.log(base);
```
```js
logBase(10, 10); // 1
logBase(100, 10); // 2
```