Skip to content

Instantly share code, notes, and snippets.

@mbburch
Last active December 15, 2015 18:10
Show Gist options
  • Save mbburch/1458e1e89f53c2a2d0d5 to your computer and use it in GitHub Desktop.
Save mbburch/1458e1e89f53c2a2d0d5 to your computer and use it in GitHub Desktop.
Remote Work 12/15
function countdown(n) {
if (n < 0) { return n };
console.log(n);
countdown(n-1);
}
countdown(4);
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();
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