Languages
[Edit]
EN

JavaScript - example, how to calculate logarithm with custom base?

1 points
Created by:
Marcin
15740

This shows a logarithmic function calculation with own base in JavaScript.

Note: read this article to see Math.log() method documentation.

2. Logarithm with custom base custom method example

// ONLINE-RUNNER:browser;

function calculateLogarithm(base, x) {
	var a = Math.log(x);
    var b = Math.log(base);
  
    return a / b;
}

// Logarithm with custom base:
//                               base    x               y
console.log( calculateLogarithm( 2,      2      ) ); //  1
console.log( calculateLogarithm( 2,      4      ) ); //  2
console.log( calculateLogarithm( Math.E, Math.E ) ); //  1
console.log( calculateLogarithm( 3,      9      ) ); // ~2
console.log( calculateLogarithm( 3,      81     ) ); // ~4
console.log( calculateLogarithm( 10,     10     ) ); //  1

 

Native Advertising
50 000 ad impressions - 449$
🚀
Get your tech brand or product in front of software developers.
For more information contact us:
Red dot
Dirask - friendly IT community for everyone.

❤️💻 🙂

Join