I need your help with the following: I'm trying to develop a function that is supposed to check whether two argument strings are rotationally equal to each other. Like, 'abcd' would become 'cdab' if we rotate that clockwise twice, so my function is supposed to return 'true' if the above strings are supplied as arguments. My initial idea to solve this was to check whether the constant shift between each character in both strings exists, so I tried
function areRotEq (str1, str2) {
var shift = null;
for(char of str1){
if(!shift) shift = str2.indexOf(char);
else if (shift != str2.indexOf(char)) return false
}
return true;
}
But, it fails to evaluate even the above simple strings properly and returns 'false'. If you could point me to the right direction to figure out why my code is not working or maybe suggest some more effective method to solve my problem that would be much appreciated. Thank you in advance!