Swift 3 Challenge 3: Order

Nesting-Dolls

Continuing our Swift 3 Challenges today’s challenge has to do with order.

Problem Description:

Given three ints, first, second, third, return true if
the second is greater than first, and third is greater than second.
However, with the exception that if the parameter “itsOk” is true,
second does not need to be greater than first but still better be less than third.

Test Cases:

Challenge-3-Test-Cases

Try this before you look at my solution.

Seriously – try it yourself.

Last chance.

Okay – here is my solution.

Challenge-3-Solution

And using the ternary operator we can get this down to one line of code.

Challenge-3-Solution-One-Line

You can play with my first solution or with my one-liner at the IBM Swift Sandbox.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s