How to find the logarithm of a number with specified base

・0 min read

Find the logarithm of a number (y) with specified base (x). logxY

function baseLog(x, y) {
  return Math.log(y) / Math.log(x);
}

Usage:

console.log(baseLog(5, 25)); // 2
console.log(baseLog(7, 49)); // 2
console.log(baseLog(2, 8)); // 3
console.log(baseLog(4, 64)); // 3
console.log(baseLog(2, 16)); // 4

Subscribe

Receive updates on new posts.