Skip to content

Instantly share code, notes, and snippets.

@Leo7654
Created July 27, 2016 08:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Leo7654/8eecf654ddefdfd2f22be0b59b208cbb to your computer and use it in GitHub Desktop.
Save Leo7654/8eecf654ddefdfd2f22be0b59b208cbb to your computer and use it in GitHub Desktop.
Shifting Window: Finding Maximum elements within 1 hour window.
// Shifting Window
// Finding Maximum elements within 1 hour window.
var inputs = [1, 2, 3, 4, 5, 6, 7, 3599, 3600, 3601, 3602, 3603];
var max = 0;
var _window = [];
for(var t of inputs) {
_window.push(t);
var val = 0;
for(var tt of likeWindow) {
if (tt < t-3600000) {
likeWindow.shift();
continue;
}
val ++;
}
max = max > val ? max : val;
}
console.log('1HourWindowMax: '+max);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment