[771. Jewels and Stones] #tags: leetcode, leetcode/Hash Table
// basic solution
// time complexity: sort O(nlogn), map + filter O(n^2)
// total time complexity: O(n^2)
/**
* @param {string} J
* @param {string} S
* @return {number}
*/
var numJewelsInStones = function(J, S) {
const sortedS = _.sortBy(S);
return _.map(J, j => {
return _.filter(sortedS, s => s === j).length;
})
.reduce((len1, len2) => len1 + len2)
};