Commit d935a2a8 d935a2a8b7d32cf0681041a5deec472da766baaf by Harrison Reiser Committed by Nicolas Perriault

fix math in the 10^9 range

1 parent bb3dec01
......@@ -15,7 +15,7 @@ casper = require('casper').create verbose: true
casper.fetchScore = ->
@evaluate ->
result = document.querySelector('#resultStats').innerText
~~(/Environ ([0-9\s]{1,}).*/.exec(result)[1].replace(/\s/g, ''))
parseInt /Environ ([0-9\s]{1,}).*/.exec(result)[1].replace(/\s/g, '')
terms = casper.cli.args # terms are passed through command-line arguments
......@@ -38,7 +38,7 @@ casper.each terms, (self, term) ->
self.echo "#{term}: #{score}"
casper.run ->
scores.sort -> (a, b) -> b.score - a.score;
winner = scores[0]
winner = x for x in scores when x.score > winner.score
@echo "Winner is #{winner.term} with #{winner.score} results"
@exit()
......
......@@ -16,7 +16,7 @@ var casper = new require('casper').create({
casper.fetchScore = function() {
return this.evaluate(function() {
var result = document.querySelector('#resultStats').innerText;
return ~~(/Environ ([0-9\s]{1,}).*/.exec(result)[1].replace(/\s/g, ''));
return parseInt(/Environ ([0-9\s]{1,}).*/.exec(result)[1].replace(/\s/g, ''));
});
};
......@@ -45,10 +45,10 @@ casper.each(terms, function(self, term, i) {
});
casper.run(function(self) {
scores.sort(function(a, b) {
return b.score - a.score;
});
var winner = scores[0];
for (var i = 0, len = scores.length; i < len; i++)
if (scores[i].score > winner.score)
winner = scores[i];
self.echo('winner is "' + winner.term + '" with ' + winner.score + ' results');
self.exit();
});
......