Created
August 29, 2012 14:09
-
-
Save JCMais/3513124 to your computer and use it in GitHub Desktop.
Javascript implementation of the Itearated Logarithm, just for fun
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Javascript implementation of the Itearated Logarithm {@link http://en.wikipedia.org/wiki/Iterated_logarithm} | |
* @author Jonathan Cardoso | |
* | |
* @param {Number} n The number to get the iterated logarithm. | |
* @return {Number} | |
*/ | |
var iteratedLog = function( n ) { | |
var result = 0; | |
if( n > 1 ) { | |
++result; | |
result += iteratedLog( Math.log( n ) / Math.log( 2 ) ); | |
} | |
return result; | |
} | |
console.log( iteratedLog( 1 ) ); //0 | |
console.log( iteratedLog( 2 ) ); //1 | |
console.log( iteratedLog( 4 ) ); //2 | |
console.log( iteratedLog( 16 ) ); //3 | |
console.log( iteratedLog( 65536 ) );//4 | |
//console.log( iteratedLog( Math.pow( 2, 65536 ) ) ); //5 - Probably the slowest thing in the universe |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment