Re:FizzBuzz in ten languages
by thanatos_dem on Monday December 31, 2018 @04:40PM
(#18797202)
Unless I’m missing something, your second example seems to be the one in the article.
Did the author change it?
Edit: just saw the comments on the article. Yes, she did.
Re:FizzBuzz in ten languages
by malloryerik on Monday December 31, 2018 @11:59PM
(#18799014)
That looks so much like Elixir.
for x <- 1..100 do
case [rem(x, 3), rem(x, 5)] do
[0, 0] -> IO.puts("FizzBuzz")
[0, _] -> IO.puts("Fizz")
[_, 0] -> IO.puts("Buzz")
_ -> x
end
end
Re:FizzBuzz in ten languages
by CleanShirt on Tuesday January 01, 2019 @04:29AM
(#18799544)
Any language that has pattern matching looks similar. Much nicer than if/else/switch.
The Rust example looks a bit strange, since you're matching on a variable, but don't actually use it.
Instead, you could write the match like this:
...or even like this: Furthermore, inclusive ranges can be written like this: