Leetcode 1512. Number of Good Pairs
1 2 3 4 5 6 7 8 9 10 11 12 | /** * @param {string} jewels * @param {string} stones * @return {number} */ var numJewelsInStones = function(jewels, stones) { let count = 0 for (let i in jewels) { count += [...stones].filter(stone => stone === [...jewels][i]).length } return count }; | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 | /** * @param {string} jewels * @param {string} stones * @return {number} */ var numJewelsInStones = function(jewels, stones) { let result = 0; for(let i = 0; i < stones.length; i++) { if(jewels.indexOf(stones.charAt(i)) >= 0) result++; } return result; }; | cs |