Created
September 16, 2021 08:41
-
-
Save joawan/98d4a59a9ee1c1ce4d80b87ec9a53c55 to your computer and use it in GitHub Desktop.
Grabbing matching teams from input
This file contains hidden or 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
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