I have tried to write JavaScript code to check whether I can form a word from the given string (jumbled):
function findWord(word, jumbledLetters, isSameLength) {
if(isSameLength && word.length !== jumbledLetters.length)
return false;
var uniquePosition = {};
for(var i = 0; i< word.length; i++)
for(var j=0; j< jumbledLetters.length; j++){
if(word[i] === jumbledLetters[j] && j !== uniquePosition[j]) {
uniquePosition[j] = j;
break;
}
}
return Object.keys(uniquePosition).length === (word.length);
}
I could do this with string permutationstring permutation with minor changes, but I tried something like the above one. Could you please suggest refactoring to be done for the above code?