Skip to content

Instantly share code, notes, and snippets.

@dobakay
Created March 15, 2016 10:11
Show Gist options
  • Save dobakay/d1ec7d5ea6f3438d1f40 to your computer and use it in GitHub Desktop.
Save dobakay/d1ec7d5ea6f3438d1f40 to your computer and use it in GitHub Desktop.
/*
Assume you have a method isSubstring which checks if one word is a substring of
another. Given two strings, s1 and s2, write code to check if s2 is a rotation of s1 using
only one call to isSubstring (i.e., “waterbottle” is a rotation of “erbottlewat”).
*/
function isRotation(str1, str2) {
if(str1.length > 0 && str1.length === str2.length) {
var concatStr = str1 + str1;
return concatStr.indexOf(str2) !== -1;
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment