Skip to content

Instantly share code, notes, and snippets.

@ms314006
Created August 5, 2023 08:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ms314006/1a3f861d8cc43a200056800df3f07d08 to your computer and use it in GitHub Desktop.
Save ms314006/1a3f861d8cc43a200056800df3f07d08 to your computer and use it in GitHub Desktop.
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