Created
July 27, 2016 08:41
-
-
Save Leo7654/8eecf654ddefdfd2f22be0b59b208cbb to your computer and use it in GitHub Desktop.
Shifting Window: Finding Maximum elements within 1 hour window.
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
// 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