Skip to content

Instantly share code, notes, and snippets.

@kfarst
Last active June 6, 2017 19:47
Show Gist options
  • Save kfarst/a762ad0de5fdc32c0b4ebdbec9fa0a69 to your computer and use it in GitHub Desktop.
Save kfarst/a762ad0de5fdc32c0b4ebdbec9fa0a69 to your computer and use it in GitHub Desktop.
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