Skip to content

Instantly share code, notes, and snippets.

@williamrjribeiro
Last active March 19, 2021 10:08
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save williamrjribeiro/4ea30eb3a942c883fde1068500c6b0cb to your computer and use it in GitHub Desktop.
Save williamrjribeiro/4ea30eb3a942c883fde1068500c6b0cb to your computer and use it in GitHub Desktop.
JavaScript Prefix Sum Function
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