Blogger

Delete comment from: Java67

My solution in Javascript(This is working for string only not for numbers)

function match(str1, str2) {
var count = str2[0];
debugger;
if(str1.length !== str2.length) {
return false
} else {
for(var i = 1; i <= str2.length; i++) {
if(str2[i].charCodeAt() >= 97 && str2[i].charCodeAt() <= 122) {
count = count.concat(str2[i]);
} else {
break;
}
}
}

if(str1.includes(count)) {
var sub = str2.substr(count.length);
var newSub = sub.concat(count);
for(var j = 0; j <= str1.length - 1; j++) {
if(str1[j] === newSub[j]) {
continue
} else {
return false
}
}
} else {
return false
}

return true
}

match("KanchanTyagi", "TyagiKanchan")

May 12, 2020, 7:18:02 AM


Posted to How to check if strings are rotations of each other in Java? String Rotation Example Solution

Google apps
Main menu