Scheme Exercises

back to exercise list       previous     next

Group:     Exercise: 47/48 

closer-to:  Is the first number closer to the second number or to the third number?

Create the function "closer-to" which will be given 3 numbers, let's say, "first", "second" and "third". We want to know whether first is closer to second, or first is closer to third. Return either second (if first is closer to it than to third) or third if not. If first is equal distance from both, return third.
Examples: closer-to(7 10 12) -> 10
closer-to(2 6 -1) -> -1
closer-to(3 2 4) -> 4