Skip to content

Instantly share code, notes, and snippets.

@3rd-Eden
Created August 31, 2010 20:50
Show Gist options
  • Save 3rd-Eden/559729 to your computer and use it in GitHub Desktop.
Save 3rd-Eden/559729 to your computer and use it in GitHub Desktop.
Node knockout positions calculator
(function( $ ){
var totals = [];
var current;
var teams = $("tr td a").each(function( index ){
if( this.innerHTML.toLowerCase() == "speedo" ){
current = index;
}
});
$("tr.final").each(function( index ){
var td = $("td", this );
var total = 0;
td.each(function(){
var tmp = parseFloat( this.innerHTML );
if( tmp !== NaN && tmp !== "NaN" && tmp ){ total += tmp;
}
});
totals[ index ] = {
total: total,
index: index,
row: this,
overall: parseFloat( td[1].innerHTML ),
utility: parseFloat( td[2].innerHTML ),
design: parseFloat( td[3].innerHTML ),
innovation: parseFloat( td[4].innerHTML ),
completeness: parseFloat( td[5].innerHTML ),
popularity: parseFloat( td[6].innerHTML )
};
});
['total', 'utility', 'design','innovation', 'completeness', 'popularity' ].forEach(function( val ){
totals.sort(function(a,b){
return b[ val ] - a[ val ];
});
totals.forEach(function( obj, index ){
if( obj.index == current ){
console.info("Current position [" + val + "]:" + ( index + 1 ) );
}
});
});
['total', 'utility', 'design','innovation', 'completeness', 'popularity' ].forEach(function( val ){
totals.sort(function(a,b){
return b[ val ] - a[ val ];
});
var firstplace = totals[0];
console.log("First position [" + val + "]: " + teams[ firstplace.index ] );
});
})( jQuery )
@3rd-Eden
Copy link
Author

3rd-Eden commented Sep 1, 2010

To adapt the script for you usage, update line 6 to use your own team name.

This will output your over position in the ranking.
The second batch of outputs will display the overall first places.

You can execute this script directly in to your browsers console :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment