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
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#