Created
December 15, 2015 18:52
-
-
Save 7hoenix/199f2a2c6ee2e2566c08 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
function countdown (num) { | |
if (num >= 0) { return console.log (0) }; | |
return console.log(countdown (num - 1)); | |
} | |
countdown (5); |
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 generated = []; | |
while (true) { | |
var length = generated.length; | |
if (length < 1) { | |
generated.push(1); | |
} else { | |
var nextFactorial = generated[length - 1] + 1; | |
var calculated = nextFactorial * generated[length - 1]; | |
generated.push(calculated); | |
yield generated[generated.length - 1]; | |
} | |
} | |
} | |
var factorial = factorialGenerator(); | |
console.log(factorial.next().value); // 1 | |
console.log(factorial.next().value); // 2 | |
console.log(factorial.next().value); // 6 | |
console.log(factorial.next().value); // 24 | |
console.log(factorial.next().value); // 120 |
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 (number, fibNumbers) { | |
if (!fibNumbers) { | |
var fibNumbers = [1, 1]; | |
} | |
fibNumbers.push(fibNumbers[fibNumbers.length - 1] + fibNumbers[fibNumbers.length - 2]); | |
if (fibNumbers.length < number) { | |
fibonacci (number, fibNumbers); | |
} else { | |
console.log (fibNumbers); | |
} | |
} | |
fibonacci (10); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment