Created
September 16, 2016 15:35
-
-
Save anonymous/c4871105e75ab30584fe03497feda6b8 to your computer and use it in GitHub Desktop.
TryCF Gist
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
<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