Skip to content

Instantly share code, notes, and snippets.

@debabratakarfa
Last active November 28, 2019 22:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save debabratakarfa/4eea4145e470fca631ee730983bd93f5 to your computer and use it in GitHub Desktop.
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)
// 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