FizzBuzz
FizzBuzz
The classic. Walk the numbers 1 to n and, for each, decide what string to add to a list:
- divisible by both 3 and 5 →
FizzBuzz - divisible by 3 →
Fizz - divisible by 5 →
Buzz - otherwise → the number itself, as a string
Check the "both" case first, or a multiple of 15 will be caught by the 3 test alone.
FizzBuzz
O clássico. Percorra os números de 1 a n e, para cada um, decida qual string adicionar a uma lista:
- divisível por ambos 3 e 5 →
FizzBuzz - divisível por 3 →
Fizz - divisível por 5 →
Buzz - caso contrário → o próprio número, como string
Verifique o caso "ambos" primeiro, ou um múltiplo de 15 será capturado apenas pelo teste de 3.
Write fizzbuzz(n) returning a list for the numbers 1..n: Fizz if divisible by 3, Buzz if by 5, FizzBuzz if by both, otherwise the number as a string. · Escreva fizzbuzz(n) retornando uma lista para os números 1..n: Fizz se divisível por 3, Buzz se por 5, FizzBuzz se por ambos, caso contrário o número como string.
Click Run to see the output here. · Clique em Executar para ver a saída aqui.