JavaScript ES6 solution (Runtime: 84 ms, faster than 94.77%)
Some of the top rated JS solutions for this problem use filter, but because that creates a new array for which we then access the length property, it seems like
Some of the top rated JS solutions for this problem use `filter`, but because that creates a new array for which we then access the `length` property, it seems like using `reduce` to count would be more memory efficient and, given a large enough input, time efficient (for constructing the output array). \n\n1. Construct a `ruleHash` object so that we can quicky convert `ruleKey` to its corresponding index. \n2. Using reduce, iterate through the `items` array. \n3. If we find that an item\'s value matches the `ruleValue`, increment `count`. \n4. The return value of our `reduce` function will be our `count`. \n\nTime: O(n)\nSpace: O(1)\n\n```\nconst countMatches = (items, ruleKey, ruleValue) => {\n    const ruleHash = {\n        type: 0,\n        color: 1,\n        name: 2,\n    }\n    const ruleIdx = ruleHash[ruleKey];\n    \n    return items.reduce((count, item) => {\n        if (item[ruleIdx] === ruleValue) count++;\n        return count;\n    }, 0);\n};\n```\n\nOr, written with an implicit return and a ternary (I prefer to use ternaries when assigning a variable rather than specifying a return value, but it\'s nice to collapse that logic): \n\n```\nconst countMatches = (items, ruleKey, ruleValue) => {\n    const ruleHash = {\n        type: 0,\n        color: 1,\n        name: 2,\n    }\n    const ruleIdx = ruleHash[ruleKey];\n    \n    return items.reduce((count, item) => (\n        item[ruleIdx] === ruleValue ? ++count : count\n    ), 0);\n};\n```\n\nFor a fake all implicit returns version, we can move the `ruleHash` constant outside of the function declaration: \n\n```\nconst RULE_HASH = {\n    type: 0,\n    color: 1,\n    name: 2,\n};\n\nconst countMatches = (items, ruleKey, ruleValue) => (\n    items.reduce((count, item) => (\n        item[RULE_HASH[ruleKey]] === ruleValue ? ++count : count\n    ), 0)\n);\n```\n\nThe solutions provided run between 84 ms (faster than 94.77%) and 90ms, and around 42mb for memory. \n\n... and, because why not, here\'s a solution without the hash:\n\n```\nconst countMatches = (items, ruleKey, ruleValue) => (\n    items.reduce((count, item) => {\n        let checkingValue;\n        \n        switch (ruleKey) {\n            case "type":\n                checkingValue = item[0];\n                break;\n            case "color":\n                checkingValue = item[1];\n                break;\n            default:\n                checkingValue = item[2];\n        }\n\n        if (checkingValue === ruleValue) count++;\n        return count;\n    }, 0)\n);\n```
['JavaScript']