문제 링크 : Count Items Matching a Rule
/**
* @param {string[][]} items
* @param {string} ruleKey
* @param {string} ruleValue
* @return {number}
*/
var countMatches = function(items, ruleKey, ruleValue) {
return items.reduce( (acc, cur) => {
if(ruleKey === 'type' && ruleValue === cur[0]) acc+=1
if(ruleKey === 'color' && ruleValue === cur[1]) acc+=1
if(ruleKey === 'name' && ruleValue === cur[2]) acc+=1
return acc
}, 0)
};
/**
* @param {string[][]} items
* @param {string} ruleKey
* @param {string} ruleValue
* @return {number}
*/
var countMatches = function(items, ruleKey, ruleValue) {
const keys = {
type: 0,
color: 1,
name: 2
}
return items.filter(item => item[keys[ruleKey]] === ruleValue).length
};