Created
September 3, 2013 12:59
-
-
Save unfo/6423574 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
function (input) { | |
return _.reduce(input, function(memo,val) { | |
memo.nums.push(val); // enqueue the current iterated value | |
if (memo.nums.length >= 5) { | |
while (memo.nums.length > 5) // dequeue excessive items | |
memo.nums.shift(); | |
var product = _.reduce(memo.nums, function(product, number) { return product * number; }, 1); | |
memo.high = Math.max(product, memo.high); | |
} | |
return memo; // important to return the memo object so it doesn't | |
// get emptied while looping the material. | |
}, { "nums": [], "high": 0 }).high; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment