Skip to content

Instantly share code, notes, and snippets.

@danielrobertson
Created October 7, 2015 15:17
Show Gist options
  • Save danielrobertson/a8bfa41b74a34271525d to your computer and use it in GitHub Desktop.
Save danielrobertson/a8bfa41b74a34271525d to your computer and use it in GitHub Desktop.
Are two strings a rotation of one another
var isRotation = function(s1, s2) {
return (s1.length === s2.length) && ((s1 + s1).indexOf(s2) !== -1);
};
s1 = "stackoverflow"
s2 = "tackoverflows"
s3 = "ackoverflowst"
s4 = "overflowstack"
s5 = "ovegflgwsgacg"
console.log(isRotation(s1, s1));
// -> true
console.log(isRotation(s1, s2));
// -> true
console.log(isRotation(s1, s3));
// -> true
console.log(isRotation(s1, s4));
// -> true
console.log(isRotation(s1, s5));
// -> false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment