Created
August 5, 2023 08:07
-
-
Save ms314006/1a3f861d8cc43a200056800df3f07d08 to your computer and use it in GitHub Desktop.
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
class Guards { | |
constructor() { | |
this.guards = []; | |
} | |
addGuards(guards) { | |
if (Array.isArray(guards)) { | |
this.guards = […this.guards, …guards]; | |
} else { | |
throw new Error('guards should be a array'); | |
} | |
} | |
execute() { | |
const invalidGuard = this.guards.find(({ isValid }) => !isValid); | |
if (invalidGuard) { | |
return { isValid: false }; | |
} | |
return { isValid: true }; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment