INNER CODE UNIT · JavaScript
getGameWithOptionalFilter
homerchen19/nba-go · src/command/game/index.js:28
const getGameWithOptionalFilter = async (games, option) => {
if (option.filter && option.filter.split('=')[0] === 'team') {
// TODO: Add more robust filtering but use team as proof of concept
const components = option.filter.split('=');
const team = components[1].toLowerCase();
const potentialGames = games.filter(
data =>
`${data.home.city.toLowerCase()} ${data.home.nickname.toLowerCase()}`.indexOf(
team
) !== -1 ||
`${data.visitor.city.toLowerCase()} ${data.visitor.nickname.toLowerCase()}`.indexOf(
team
) !== -1
);
if (!potentialGames.length) {
error(`Can't find any teams that match ${team}`);
} else if (potentialGames.length === 1) {