Update and rename logarithmCalculator.md to logBase.md
This commit is contained in:
committed by
GitHub
parent
59c9aa82ae
commit
34c921fa4c
17
snippets/logBase.md
Normal file
17
snippets/logBase.md
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
---
|
||||||
|
title: logBase
|
||||||
|
tags: math,beginner
|
||||||
|
---
|
||||||
|
|
||||||
|
Returns 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
|
||||||
|
```
|
||||||
@ -1,19 +0,0 @@
|
|||||||
---
|
|
||||||
title: logarithmCalculator
|
|
||||||
tags: math,beginner
|
|
||||||
---
|
|
||||||
|
|
||||||
Calculates the logarithm from given number in given base.
|
|
||||||
|
|
||||||
- Use `Math.log(value)` to get the logarithm from value
|
|
||||||
- Use `Math.log(base)` to get the logarithm from base
|
|
||||||
- Divide `Math.log(value)` by `Math.log(base)` to get logarithm of given value in given base.
|
|
||||||
|
|
||||||
```js
|
|
||||||
const logarithmCalculator = (value, base) => Math.log(value) / Math.log(base)
|
|
||||||
```
|
|
||||||
|
|
||||||
```js
|
|
||||||
logarithmCalculator(10, 10); // 1
|
|
||||||
logarithmCalculator(100, 10); // 2
|
|
||||||
```
|
|
||||||
Reference in New Issue
Block a user