Last active
November 28, 2019 22:18
-
-
Save debabratakarfa/4eea4145e470fca631ee730983bd93f5 to your computer and use it in GitHub Desktop.
Check two string (May be they are not in order but contain similar string char)
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
// if we pass rats and star will be match | |
// if we pass star and wars then it will be not match | |
function checkStr(A, B) { | |
if(A && B) { | |
var x = A.split('').sort(), | |
y = B.split('').sort(), | |
count = 0; | |
if(x.length != y.length) { | |
return; | |
} | |
for(i=0; i< x.length; i++) { | |
if (x[i] === y[i]) { | |
count++; | |
} | |
} | |
if(x.length === count) { | |
return 'Match'; | |
} | |
} | |
} | |
var returndata = checkStr('star', 'rats'); | |
var returndataAnotherTest = checkStr('abcdw', 'acbw'); | |
var returndataTestNull = checkStr(null, 'acbw'); | |
var returndataAnotherTestNull = checkStr('abdw', null); | |
var returndataBothNull = checkStr(null, null); | |
console.log(returndata); | |
console.log(returndataAnotherTest); | |
console.log(returndataTestNull); | |
console.log(returndataAnotherTestNull); | |
console.log(returndataBothNull); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment