Skip to content

Instantly share code, notes, and snippets.

@smiled0g
Last active June 29, 2018 01:18
Show Gist options
  • Save smiled0g/f667625ca8250e8b30e940855ff0fd55 to your computer and use it in GitHub Desktop.
Save smiled0g/f667625ca8250e8b30e940855ff0fd55 to your computer and use it in GitHub Desktop.
function check(letterPool, word) {
// S1
const map = {}
for (let i=0; i<letterPool.length; i++) {
const character = letterPool[i]
if (map[character] === undefined) {
map[character] = 1
} else {
map[character] += 1
}
}
// S2
const charInWord = word.split('')
for (let i=0; i<charInWord.length; i++) {
const character = charInWord[i]
if (map[character]) {
map[character] -= 1
} else {
return false
}
}
return true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment