Created
April 17, 2019 06:32
-
-
Save jcar787/c50c8aa88dbf570e17863eff9f7080a1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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