|
Hi, I think this solutions is a bit cleaner than the proposed in the video. It prevents the nested code and the duplication of the check for the case 5:
What do you think? |
|
Nice job! Indeed it is cleaner. Here'a challenge for you. Think about your solution, and reduce it to one line of code! Try it first before looking at > FizzBuzz in One Line |
|
Ey @Obelix! It's cool you solutions, very interesting to play with it. But it's more difficult to read. Thanks for your review! |
|
Making that a one-liner is just mean to whomever follows you on future edits. After 35 years doing this, readable, maintainable code wins every single time. "Clever" gets nothing but contempt during a code review, updates, or bug fix. :D |
|
Antonio chides:
Chris agrees with:
Hey! I agree with both of you. I was just trying to have fun and test the boundaries. We had a lunchtime coding contest at work last year, and I submitted a similar entry, for fun. |
|
|
|
Hi sorry to bother you i really liked that approach But i cant really understand the print call. Could you maybe break it down for me? ^^ |
|
Remember both codes (Antonio's above and Obelix's linked) basically return the same thing - multiples of 3 are Fizz, multiples of 5 are Buzz and multiples of 15 are FizzBuzz. The key for me to understand Obelix's code was to replace the 🍺 with an i (that is what Antonio uses above). This is just a variable name and it can be anything you want. Personally, I think Obelix's version is hilarious and awesome! Can't wait to use this somewhere in my code just for the fun of it. |
SAVE 50% All our books and bundles are half price for Black Friday, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.