Last active
June 6, 2017 19:47
-
-
Save kfarst/a762ad0de5fdc32c0b4ebdbec9fa0a69 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 fizzBuzzCustom (fizz, buzz, firstDivisibility, secondDivisibility) { | |
var incrementedArray = []; | |
// Set to the argument or default to 'Fizz' | |
fizz = fizz || 'Fizz'; | |
// Set to the argument or default to 'Buzz' | |
buzz = buzz || 'Buzz'; | |
// Set to the argument or default to 3 | |
firstDivisibility = firstDivisibility || 3; | |
// Set to the argument or default to 5 | |
secondDivisibility = secondDivisibility || 5; | |
for (var i = 1; i <= 100; i++) { | |
if (i % firstDivisibility === 0 && i % secondDivisibility === 0) { | |
incrementedArray.push(fizz + buzz); | |
} else if (i % firstDivisibility === 0) { | |
incrementedArray.push(fizz); | |
} else if (i % secondDivisibility === 0) { | |
incrementedArray.push(buzz); | |
} else { | |
incrementedArray.push(i); | |
} | |
} | |
return incrementedArray; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment