Top community members
All Wiki Articles Create Wiki Article

Welcome to Dirask IT community! ❤ 💻
We are community of people that helps each other.

If you think you have some skills to help others

help someone and become a part of our community - List Q & A

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

0 contributions
1 points

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

 

0 contributions

Checkout latest Findings & News:

Checkout latest questions:

Checkout latest wiki articles:

Hey 👋
Would you like to know what we do?
  • Dirask is IT community, where we share coding knowledge and help each other to solve coding problems.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.
Read more