Count Items Matching a Rule

EasyArrayString

Solution

export function countMatches(items: string[][], ruleKey: string, ruleValue: string): number {
  const itemIndex = ruleKey === 'type' ? 0 : ruleKey === 'color' ? 1 : 2;
  return items.filter((item) => item[itemIndex] === ruleValue).length;
}