Skip to content

Instantly share code, notes, and snippets.

Avatar
🦎
What's up?

William R. J. Ribeiro williamrjribeiro

🦎
What's up?
View GitHub Profile
View keybase.md

Keybase proof

I hereby claim:

  • I am williamrjribeiro on github.
  • I am wrjr (https://keybase.io/wrjr) on keybase.
  • I have a public key ASDEXh0AK8GG3eqjijZFY6KtrX9PQmS0HL5D_Vz9wOA2tgo

To claim this, I am signing this object:

@williamrjribeiro
williamrjribeiro / constantarraysum.js
Last active Jul 1, 2016
Constant Time Array Sum using Prefix Sums
View constantarraysum.js
function prefixSum(A) {
var i = 0,
l = A.length,
sum = A[0],
P = new Array(l);
P[0] = sum;
while (++i < l) {
sum += A[i];
P[i] = sum;
}
View lineararraysum.js
function sumArrayLinear(A, start, end){
end = (end >= A.length ? A.length - 1: end); // avoid Out of Bounds
var total = 0;
for(start; start <= end; start++)
total += A[start];
return total;
}
var arr = [2,5,7,4,2,4,3,3,2,1,8,6,9,7,5,4,2,5,6,7,9,0,8,5,3,2,4,5,6,7,8,5,6],
arrSum = [];
@williamrjribeiro
williamrjribeiro / prefixsum.js
Last active Nov 8, 2017
JavaScript Prefix Sum Function
View prefixsum.js
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];
You can’t perform that action at this time.