Ad
  • Custom User Avatar

    I don't think you need that fatalError in there as you'll probably never need to have it. The days should always be between 1 and any allowed number in the Integer type. The switch case looks pretty clean - I like the same line for case and result. First case should probably have been 1...2 ..because there will never be 0 rental days and I checked ...they're not using zero base. The next case probably could have been 3...6 and then finally just default as seen in psmilliorn's solution which would be discount (or descount as you've spelled it) = 50. Could have also used the switch case return design pattern to save on lines of code too, but it all still works. I hope my feedback was useful. Thanks for sharing your solution.

  • Custom User Avatar

    There's a lot going on in this solution that could have been commented on and you just wanted to point out their misspelling? To each their own..

  • Custom User Avatar

    I feel like this one looks nice in terms of readability, but the number of lines seems bulky for the job it's doing. Could probably shorten it up by putting the returns on the same line as the cases. x should be a constant (let x = 40). Other than that it looks great. I'm glad I got to see it done this way because in many ways it makes sense and if I find myself thinking this way on a problem I hope I remember how cleanly you did it.

  • Custom User Avatar

    Feels like a good clean approach that maintains readability and optimization. I like it. I had gone for the nested ternary option, but sometimes I feel like nested ternaries are barf ugly.

  • Custom User Avatar

    Beautiful. I forgot about those techniques. Thanks for the reminder.