Another day, another Swift 3 puzzle. This one is about singing birds. Remember to try it before you look at my solution.
The problem description states:
The birds in Florida like to sing during favorable temperatures.
In particular, they sing if the temperature is between 60 and 90 (inclusive).
Unless it is summer, then the upper limit is 100 instead of 90.
Given an int temperature and a boolean isSummer,
return true if the birds are singing and false otherwise.
My three test cases are:
print(birdsSinging(temp: 70, isSummer: false)) // true
print(birdsSinging(temp: 95, isSummer: false)) // false
print(birdsSinging(temp: 95, isSummer: true)) // true
My Swift 3 code is a one-liner using the ternary operator:
I tend not to like one-liners but this one is pretty legible.
You can play with my code at the IBM Swift Sandbox.