Created
January 27, 2017 20:41
-
-
Save elimence/af24e07a3c911389163a1e20769229d2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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