Count Items Matching a Rule

Easy

items[i] = [type, color, name] describes item i. Given a ruleKey (type, color or name) and a ruleValue, return how many items match.

Example 1

countMatches()
Input
items = [["phone","blue","pixel"],["computer","silver","lenovo"],["phone","gold","iphone"]], ruleKey = "color", ruleValue = "silver"
Output
1

Example 2

countMatches()
Input
items = [["phone","blue","pixel"],["computer","silver","lenovo"],["phone","gold","iphone"]], ruleKey = "type", ruleValue = "phone"
Output
2
Constraints
1 <= items.length <= 10^4
`ruleKey` is one of `type`, `color`, `name`.

Topics

ArraysStrings

Implement countMatches in the editor and return the answer — printing it is never graded.