Skip to content

Instantly share code, notes, and snippets.

@desmondrawls
Last active May 9, 2019 15:23
Show Gist options
  • Save desmondrawls/e5505db44c41d20d00d88ee7e69d1909 to your computer and use it in GitHub Desktop.
Save desmondrawls/e5505db44c41d20d00d88ee7e69d1909 to your computer and use it in GitHub Desktop.
export const fizzbuzz = (i) => {
var thingsItsNotDivisibleBy = []
var stringI = i.toString()
var tempI = i
var elementsOfStringI = () => {
var elements = []
for(i = 0; i < stringI.length; i++)
if(parseInt(stringI[i]) != 0) elements = [...elements, parseInt(stringI[i])]
return elements
}
var sumOfElementsOfStringI =
elementsOfStringI()
.reduce((acc, next) => acc + next, 0)
if(sumOfElementsOfStringI % 3 != 0) thingsItsNotDivisibleBy.push(3)
if(parseInt(stringI[stringI.length - 1]) % 5 != 0) thingsItsNotDivisibleBy.push(5)
if(thingsItsNotDivisibleBy.includes(3) && thingsItsNotDivisibleBy.includes(5))
return tempI
else if (!thingsItsNotDivisibleBy.includes(3))
if(!thingsItsNotDivisibleBy.includes(5))
return 'FizzBuzz'
else return 'Fizz'
else return 'Buzz'
}
export const fizzbuzz = (i) => {
if (i % 15 == 0) return "FizzBuzz"
else if (i % 3 == 0) return "Fizz"
else if (i % 5 == 0) return "Buzz"
else return i;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment