Skip to content

Instantly share code, notes, and snippets.

@unfo
Created September 3, 2013 12:59
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 unfo/6423574 to your computer and use it in GitHub Desktop.
Save unfo/6423574 to your computer and use it in GitHub Desktop.
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