Skip to content

Instantly share code, notes, and snippets.

@beall49
Last active May 11, 2019 00:18
Show Gist options
  • Save beall49/9b6e734e350b076336b2b6c5cbadfdb1 to your computer and use it in GitHub Desktop.
Save beall49/9b6e734e350b076336b2b6c5cbadfdb1 to your computer and use it in GitHub Desktop.
const fizzBuzz = (start, end) => {
const range = [...Array(end).keys()].slice(start, end);
range.forEach(indx => {
if (indx % 15 === 0) {
console.log(`fizzbuzz ${indx}`);
} else if (indx % 5 === 0) {
console.log(`buzz ${indx}`);
} else if (indx % 3 === 0) {
console.log(`fizz ${indx}`);
} else {
console.log(`fail ${indx}`);
}
})
}
const args = process.argv.slice(2);
const getArg = (type) => {
const ndx = args.indexOf(type) + 1;
return parseInt(args[ndx]);
}
const min = getArg("--start") || 0;
const max = getArg('--end') || 1;
fizzBuzz(min, max);
/*
const range = Array.from({ length: (end - start) }, (_, v) => v + start)
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment