Skip to content

Instantly share code, notes, and snippets.

@joawan
Created September 16, 2021 08:41
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 joawan/98d4a59a9ee1c1ce4d80b87ec9a53c55 to your computer and use it in GitHub Desktop.
Save joawan/98d4a59a9ee1c1ce4d80b87ec9a53c55 to your computer and use it in GitHub Desktop.
Grabbing matching teams from input
const teamsFromText = (text, teams) => {
const tags = teams.reduce((acc, team) => [...acc, ...team.tags, team.name], []);
const keywords = text.toLowerCase().split(' ').filter((word) => tags.includes(word));
if (!keywords.length) {
const names = teams.map((team) => team.name).join(' ');
throw new Error(`Don't know any team to match that too. Available teams are \`${names}\`.`);
}
return teams.filter((team) => [team.name, ...team.tags].some((tag) => keywords.includes(tag)));
};
// teamsFromText('@oncall identity privacy', [ ..., all teams, ... ]); => [ ..., filtered teams, ... ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment