Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Reverse calculation of a sqrt()

i have this function.

function calculateLevel(experience) {
    console.log(Math.floor(25 + Math.sqrt(650 + 170 * experience)) / 50);
}

calculateLevel(20);

But, i want to know the reverse of this, example from level 1 get xp amount.
Example if i have level 1.76, in reverse i got 20 xp for this level.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You would do it in reverse:

function calcXP(level) {
  console.log(Math.ceil((((level * 50 - 25) ** 2) - 650) / 170));
}
calcXP(1.76) // 20

Just like in math, you would do each operation in reverse, first multiplying by 50, then subtracting 25, then squaring and subtracting 650 and dividing by 170.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading