Skip to content

Instantly share code, notes, and snippets.

@jcar787
Created April 17, 2019 06:32
Show Gist options
  • Save jcar787/c50c8aa88dbf570e17863eff9f7080a1 to your computer and use it in GitHub Desktop.
Save jcar787/c50c8aa88dbf570e17863eff9f7080a1 to your computer and use it in GitHub Desktop.
const numJewelsInStones = (jewels, stones) => {
const cache = {};
for (const j of jewels) {
cache[j] = 0
}
for (const s of stones) {
if (s in cache) {
cache[s]++;
}
}
return Object.keys(cache).reduce((ac, j) => {
ac += cache[j];
return ac;
}, 0)
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment