I'm trying to implement a function which checks whether a list of letters are all present in a word.
function wordHasLatters(word,letters){
let wordChars={};
word.split("").map(c=>wordChars[c]=true);
let ok=true;
letters.split("").map(l=>ok=ok&&(wordChars[l]!=undefined));
return ok;
}
It is all relatively elegant with using maps. What bothers me is that I cannot return from the second map if I detect that a letter is not present. So I have to use a variable and return this. This is two extra lines in the code.
Is there a way to optimize this code?