Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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