Skip to content

Instantly share code, notes, and snippets.

@S2
Created February 17, 2014 08:10
Show Gist options
  • Save S2/9046651 to your computer and use it in GitHub Desktop.
Save S2/9046651 to your computer and use it in GitHub Desktop.
var fs = require('fs');
fs.readFile('./thanks_log.txt', 'utf8', function (err, text) {
text = text.replace(/\\s/g , "");
var rows = text.split("\n")
var dataArray = [];
for( var i = 0 , arrayLength = rows.length ; i < arrayLength ; i++){
var row = rows[i];
var data = row.split("|")
dataArray.push({
date : data[1],
count : data[2],
});
}
var max = 0;
var maxI = 0;
for( var i = 0 , arrayLength = dataArray.length - 30 ; i < arrayLength ; i++){
var sum = 0;
for( var j = 0 ; j < 30; j++){
var rowNumber = i + j;
var count = dataArray[rowNumber]["count"];
sum += parseInt(count);
}
if(max < sum ){
console.log(i);
console.log(max);
max = sum
maxI = i;
}
}
console.log(max)
console.log(dataArray[maxI]["date"])
console.log(dataArray[maxI + 30]["date"])
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment