Skip to content

Instantly share code, notes, and snippets.

Created September 16, 2016 15:35
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 anonymous/c4871105e75ab30584fe03497feda6b8 to your computer and use it in GitHub Desktop.
Save anonymous/c4871105e75ab30584fe03497feda6b8 to your computer and use it in GitHub Desktop.
TryCF Gist
<cfscript>
numeric function maxSequence(required array arr){
var currentSum = 0;
return arr.reduce(function(maxSum, number){
currentSum = max(currentSum+number, 0);
return max(currentSum, maxSum);
}, 0);
}
WriteDump(maxSequence([-2, 1, -3, 4, -1, 2, 1, -5, 4]));
WriteDump(maxSequence([-2, 1, -3, 4, -1, 2, 1, -5, 4, 3]));
WriteDump(maxSequence([-2, -3, -1, -5]));
WriteDump(maxSequence([1, 4, 2, 1, 4, 3]));
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment