Last active
June 29, 2018 01:18
-
-
Save smiled0g/f667625ca8250e8b30e940855ff0fd55 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
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