Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save talentdeficit/b7005845563ec6c272acd099e81530e3 to your computer and use it in GitHub Desktop.
Save talentdeficit/b7005845563ec6c272acd099e81530e3 to your computer and use it in GitHub Desktop.
sum(listOfInts) { sum(0, listOfInts); }
sum(acc, listOfInts) {
if length(listOfInts) == 0 { return acc; }
else {
acc += head(listOfInts);
sum(acc, tail(listOfInts);
}
}
sum(listOfInts) {
acc = 0;
for(i = 0, i < length(listOfInts), i++ {
acc += listOfInts[i];
}
return acc;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment