Last active
March 19, 2021 10:08
-
-
Save williamrjribeiro/4ea30eb3a942c883fde1068500c6b0cb to your computer and use it in GitHub Desktop.
JavaScript Prefix Sum Function
This file contains hidden or 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 prefixSum(A) { | |
var i = 0, | |
l = A.length, | |
P = new Array(l), | |
sum = A[0]; | |
P[0] = sum; | |
while (++i < l) { | |
sum += A[i]; | |
P[i] = sum; | |
} | |
return P; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment