Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Javascript implementation of the Itearated Logarithm, just for fun
/**
* 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
You can’t perform that action at this time.