Skip to content

Instantly share code, notes, and snippets.

@elimence
Created January 27, 2017 20:41
Show Gist options
  • Save elimence/af24e07a3c911389163a1e20769229d2 to your computer and use it in GitHub Desktop.
Save elimence/af24e07a3c911389163a1e20769229d2 to your computer and use it in GitHub Desktop.
var myFunction = function() {
}
function myFunction() {
}
const list = [ 1, 2, 3, 4, 5 ]
function sum(nums) {
var total = 0;
for(var num : nums) {
total += num
}
}
function sum(nums) {
function add(acc, list) {
if( list.length < 1 ) {
return acc
} else {
add(acc + list.last, list.tail)
}
}
return add(0, nums)
}
sum([ 1, 2, 3 ])
add(0, [1,2,3])
add(3, [1,2])
add(5, [1])
add(6, [])
6
let
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment