Write a function named setAlarm which receives two parameters. The first parameter, employed
, is true whenever you are employed and the second parameter, vacation
is true whenever you are on vacation.
The function should return true if you are employed and not on vacation (because these are the circumstances under which you need to set an alarm). It should return false otherwise. Examples:
setAlarm(true, true) -> false
setAlarm(false, true) -> false
setAlarm(false, false) -> false
setAlarm(true, false) -> true
Good luck!
This challenge comes from Swolebrain on CodeWars. Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!
Want to propose a challenge idea for a future post? Email yo+challenge@dev.to with your suggestions!
Top comments (5)
JS
A solution in Dyalog APL:
APL does not have true/false as a dedicated "logical values", but uses 0 or 1 to indicate false/true. So this can be done with a simple calculation:
employed multiplied by not(vacation)
:Here's the table of all possible results:
OK, I cheated: my fn uses the "dyadic" syntax where you provide a left arg (employed) and a right argument (vacation). I've also written an "enhanced" version that can deal with both syntaxes:
`
Try it online!
Here is the simple solution with PHP:
Enjoy!
Haskell