Skip to content

Commit e6763b6

Browse files
authored
Merge pull request Chalarangelo#1370 from augustoscher/add-logarithm-calculator
Adding logarithm calculator for given number in given base
2 parents fab7b21 + 34c921f commit e6763b6

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

snippets/logBase.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
title: logBase
3+
tags: math,beginner
4+
---
5+
6+
Returns the logarithm of the given number in the given base.
7+
8+
- Use `Math.log()` to get the logarithm from the value and the base and divide them.
9+
10+
```js
11+
const logBase = (n, base) => Math.log(n) / Math.log(base);
12+
```
13+
14+
```js
15+
logBase(10, 10); // 1
16+
logBase(100, 10); // 2
17+
```

0 commit comments

Comments
 (0)