
😎풀이
ruleKey
를 활용하여 찾고자 하는 인덱스 검색
items
순회
2-1. 현재 요소의 값이 ruleValue
에 해당하는지 비교
2-2. 해당될 경우 matched
증가
- 확인된
matched
반환
function countMatches(items: string[][], ruleKey: string, ruleValue: string): number {
const findIdx = keyToIdx(ruleKey)
let matched = 0
for(let i = 0; i < items.length; i++) {
const curValue = items[i][findIdx]
if(curValue === ruleValue) matched++
}
return matched
};
function keyToIdx(ruleKey: string) {
switch(ruleKey) {
case 'type':
return 0
case 'color':
return 1
case 'name':
return 2
}
return 0
}