Created
June 16, 2011 03:31
-
-
Save ralphholzmann/1028622 to your computer and use it in GitHub Desktop.
Paste this in the console at ralphholzmann.com to see the char distribution
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
var obj = {}, ordered = []; | |
$.get("js/jquery-1.6.1.min.js", function( src ) { | |
src.replace(/[^\w]|\d/gi, '').split('').forEach(function( c ) { | |
obj[ c ] ? ++obj[ c ] : ( obj[ c ] = 1 ) | |
}); | |
console.log( "Object containing character frequencies", $.extend({}, obj) ); | |
(function order() { | |
var largest = 0, | |
c; | |
for ( var i in obj ) { | |
if ( obj[ i ] >= largest ) { | |
largest = obj[ i ]; | |
c = i; | |
} | |
} | |
ordered.push( c ); | |
delete obj[ c ]; | |
if ( ! $.isEmptyObject( obj ) ) { | |
order(); | |
} | |
})(); | |
console.log( "Characters ordered by frequency", ordered ); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment