Created
March 15, 2016 10:11
-
-
Save dobakay/d1ec7d5ea6f3438d1f40 to your computer and use it in GitHub Desktop.
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
/* | |
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