Skip to main content
1 of 5

Finding the given word from jumbled letters

I have tried to write a javascript code to check whether we 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);
}

We could do this with string permutation with miron changes, but i tried something like the above one. Could you guys please suggest the refactoring to be done for the above code??