From 59c9aa82ae2fcc3529b90134d0f57f28b007da8c Mon Sep 17 00:00:00 2001 From: "Augusto S. Scher" Date: Tue, 6 Oct 2020 22:55:05 -0300 Subject: [PATCH 1/2] Adding logarithm calculator for given number in given base --- snippets/logarithmCalculator.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 snippets/logarithmCalculator.md diff --git a/snippets/logarithmCalculator.md b/snippets/logarithmCalculator.md new file mode 100644 index 000000000..563c475a4 --- /dev/null +++ b/snippets/logarithmCalculator.md @@ -0,0 +1,19 @@ +--- +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 +``` From 34c921fa4c41b19c9b2b6f7876dcbf45e215672c Mon Sep 17 00:00:00 2001 From: Isabelle Viktoria Maciohsek Date: Wed, 7 Oct 2020 19:14:30 +0300 Subject: [PATCH 2/2] Update and rename logarithmCalculator.md to logBase.md --- snippets/logBase.md | 17 +++++++++++++++++ snippets/logarithmCalculator.md | 19 ------------------- 2 files changed, 17 insertions(+), 19 deletions(-) create mode 100644 snippets/logBase.md delete mode 100644 snippets/logarithmCalculator.md diff --git a/snippets/logBase.md b/snippets/logBase.md new file mode 100644 index 000000000..c55f52d73 --- /dev/null +++ b/snippets/logBase.md @@ -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 +``` diff --git a/snippets/logarithmCalculator.md b/snippets/logarithmCalculator.md deleted file mode 100644 index 563c475a4..000000000 --- a/snippets/logarithmCalculator.md +++ /dev/null @@ -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 -```