Created
May 9, 2019 06:12
-
-
Save hoangtranson/7742e1442442dcbdc1c1084cc43d036f to your computer and use it in GitHub Desktop.
Enum with static functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Weekday { | |
Monday, | |
Tuesday, | |
Wednesday, | |
Thursday, | |
Friday, | |
Saturday, | |
Sunday | |
} | |
namespace Weekday { | |
export function isBusinessDay(day: Weekday) { | |
switch (day) { | |
case Weekday.Saturday: | |
case Weekday.Sunday: | |
return false; | |
default: | |
return true; | |
} | |
} | |
} | |
const mon = Weekday.Monday; | |
const sun = Weekday.Sunday; | |
console.log(Weekday.isBusinessDay(mon)); // true | |
console.log(Weekday.isBusinessDay(sun)); // false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment