Created
March 24, 2019 11:42
-
-
Save fcarelse/2e74b353267f6fa39c5fce75c5ba6b9d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Standard fibonacci puzzle | |
function fib(n){ | |
for(var i=0,j=1,k=0;n--;i=i+j,j=k,k=i);// Semicolon required here | |
// Only return i after n has counted down | |
return i; | |
} | |
// 1,1,2,3,5,8,13,21,34,55 | |
// Standard fizzbuzz puzzle | |
function fizzbuzz(n){ | |
// If not a multiple of either then return the number | |
return n%3 && n%5? n: | |
// otherwise return string appending fizz for multiple of 3 | |
(n%3?'':'fizz')+ | |
// and append buzz for multiple of 5 | |
(n%5?'':'buzz'); | |
} | |
// 1, 2, 'fizz', 4, 'buzz', 'fizz', 7, 8 'fizz', 'buzz', 11, 'fizz', 13, 14, 'fizzbuzz' | |
// n=>n%3 && n%5? n: (n%3?'':'fizz')+(n%5?'':'buzz') | |
module.exports = {fib, fizzbuzz}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment