Skip to content

Instantly share code, notes, and snippets.

@JCMais
Created August 29, 2012 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JCMais/3513124 to your computer and use it in GitHub Desktop.
Save JCMais/3513124 to your computer and use it in GitHub Desktop.
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