diff --git a/src/code-challenges/code-challenges-002-010.js b/src/code-challenges/code-challenges-002-010.js index d6997a6..9dc1867 100644 --- a/src/code-challenges/code-challenges-002-010.js +++ b/src/code-challenges/code-challenges-002-010.js @@ -180,3 +180,16 @@ exports.iterative = function (array) { return result; }; + +/** + * Q008: String Rotation + * Problem: Find out if a string is a rotation of another string. + * E.g. 'ABCD' is a rotation of 'BCDA' but not 'ACBD' + */ + +// First make sure 'a' and 'b' are of the same length. +// Then check to see if 'b' is a substring of 'a' concatenated with 'a' + +module.exports = function (a, b) { + return a.length === b.length && (a + a).indexOf(b) > -1; +};