Last active
December 15, 2015 18:10
-
-
Save mbburch/1458e1e89f53c2a2d0d5 to your computer and use it in GitHub Desktop.
Remote Work 12/15
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
function countdown(n) { | |
if (n < 0) { return n }; | |
console.log(n); | |
countdown(n-1); | |
} | |
countdown(4); |
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
function* factorialGenerator() { | |
var num = 1; | |
var old_val = 1; | |
while (true) { | |
if (num === 1) { | |
yield 1; | |
num++; | |
} else { | |
value = (num * old_val); | |
old_val = value; | |
num++; | |
yield value; | |
} | |
} | |
} | |
var factorial = factorialGenerator(); |
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
function fibonacci(n) { | |
if (n === 1) { | |
return [1]; | |
} else if (n <= 2) { | |
return [1, 1]; | |
} | |
else { | |
var fibs = fibonacci(n - 1); | |
fibs.push(fibs[fibs.length - 1] + fibs[fibs.length - 2]); | |
return fibs; | |
} | |
}; | |
console.log(fibonacci(10)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment