Logarithm in specific base

JavaScript, Math · Oct 22, 2020

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

More like this

  • Arithmetic progression

    JavaScript, Math

    Creates an array of numbers in the arithmetic progression, starting with the given positive integer and up to the specified limit.

  • Percentile of matches

    JavaScript, Math

    Calculates the percentage of numbers in the given array that are less or equal to the given value.

  • Rounds a number to a specified amount of digits.