C# Corner
Tech
News
Videos
Forums
Trainings
Books
Events
More
Interviews
Jobs
Live
Learn
Career
Members
Blogs
Challenges
Certifications
Bounties
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Find the given word from jumbled letters using Javascript
WhatsApp
Jaganathan Bantheswaran
Dec 27
2014
2.2
k
0
0
function
findWord(word, jumbledLetters, isSameWord) {
if
(isSameWord && 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);
}
console.clear();
console.log(findWord(
'anish'
,
'shinaaaaa'
,
false
)); // prints true
console.log(findWord(
'kumar'
,
'kumardddd'
)); // prints true
console.log(findWord(
'cab'
,
'ssdsdrgfvffdgdfgerebeinaaa'
));
console.log(findWord(
'rama'
,
'raandsgsgsdgsdsdgsdgsdgdssdgsdgsdgm'
,
false
));
console.log(findWord(
'kavitha'
,
'thavikssssssa'
,
true
)); // prints false
javascript
Up Next
Find the given word from jumbled letters using Javascript