loading...

re: Daily Challenge #75 - Set Alarm VIEW POST

FULL DISCUSSION
 

Swift version:

import Foundation

/*
 SetAlarm challenge function

 @param currentlyEmployed: Bool indicating if we are currently employed.
 @param onVacation: Bool indicating if we are currently on vacation.

 @return Bool indicating if we need to set our alarm.  Only true if both employed and not on vacation.
 */
func setAlarm(currentlyEmployed:Bool, onVacation:Bool) -> Bool{
    return (currentlyEmployed && !onVacation)
}

//  run with all examples
print("Ex1 setAlarm(true,true)   -> false:     ", setAlarm(currentlyEmployed: true, onVacation: true))
print("Ex2 setAlarm(false,true)  -> false:     ", setAlarm(currentlyEmployed: false, onVacation: true))
print("Ex3 setAlarm(false,false) -> false:     ", setAlarm(currentlyEmployed: false, onVacation: false))
print("Ex4 setAlarm(true,false)  -> true:      ", setAlarm(currentlyEmployed: true, onVacation: false))


//  not exactly proper test suite, but you get the idea.
print("Passed all tests:    ", (!setAlarm(currentlyEmployed: true, onVacation: true) &&
                                !setAlarm(currentlyEmployed: false, onVacation: true) &&
                                !setAlarm(currentlyEmployed: false, onVacation: false) &&
                                setAlarm(currentlyEmployed: true, onVacation: false)))

Outputs the following:

Ex1 setAlarm(true,true)   -> false:      false
Ex2 setAlarm(false,true)  -> false:      false
Ex3 setAlarm(false,false) -> false:      false
Ex4 setAlarm(true,false)  -> true:       true
Passed all tests:     true
Program ended with exit code: 0

Overkill with all the printouts, but hey, why not?

code of conduct - report abuse