Created
February 17, 2014 08:10
-
-
Save S2/9046651 to your computer and use it in GitHub Desktop.
This file contains 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 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