Created
August 31, 2010 20:50
-
-
Save 3rd-Eden/559729 to your computer and use it in GitHub Desktop.
Node knockout positions calculator
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
(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 ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 :)