I added two solutions to the Rosetta Code FizBuzz page in Nu.
The one that was already there was quite confusing/non-intuitive to me; with string determination, and by index value fixups.
I like the match solution because it’s structurally obvious and demonstrates the record-field-value match and logical case matching:
1..100 | each {
{ x: $in, mod3: ($in mod 3), mod5: ($in mod 5), }
| match $in {
{ mod3: 0, mod5: 0, } => 'FizzBuz',
{ mod3: 0, mod5: _, } => 'Fizz',
{ mod3: _, mod5: 0, } => 'Buzz',
_ => $in.x
}
} | str join "\n"
Do you have alternative suggestions or improvements?
You must log in or register to comment.