Files
30-seconds-of-code/snippets/logarithmCalculator.md
2020-10-06 22:55:05 -03:00

488 B

title, tags
title tags
logarithmCalculator math,beginner

Calculates the logarithm from given number in given base.

  • Use Math.log(value) to get the logarithm from value
  • Use Math.log(base) to get the logarithm from base
  • Divide Math.log(value) by Math.log(base) to get logarithm of given value in given base.
const logarithmCalculator = (value, base) => Math.log(value) / Math.log(base)
logarithmCalculator(10, 10); // 1
logarithmCalculator(100, 10); // 2