Files
30-seconds-of-code/snippets/logBase.md
2020-10-07 19:14:30 +03:00

317 B

title, tags
title tags
logBase 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.
const logBase = (n, base) => Math.log(n) / Math.log(base);
logBase(10, 10); // 1
logBase(100, 10); // 2