Math.log with an optional base
Math.log = (function(){
var func = Math.log;
return function(val, base){
if ( typeof base !== 'number' ) return func(val);
return func(val) / func(base);
};
}());
For example, log base 10 of 100:
Math.log(100, 10);
Or, you can still grab the natural log by omitting the base:
Math.log(100);Written by Kevin Ennis
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Javascript
Authors
Related Tags
#javascript
Did you know?
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#