Skip to content

Commit 86a63e3

Browse files
Merge pull request #98 from wakidurrahman/feat/feat/code-challenges-008
update
2 parents a8261aa + 04d22ac commit 86a63e3

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/code-challenges/code-challenges-002-010.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,16 @@ exports.iterative = function (array) {
180180

181181
return result;
182182
};
183+
184+
/**
185+
* Q008: String Rotation
186+
* Problem: Find out if a string is a rotation of another string.
187+
* E.g. 'ABCD' is a rotation of 'BCDA' but not 'ACBD'
188+
*/
189+
190+
// First make sure 'a' and 'b' are of the same length.
191+
// Then check to see if 'b' is a substring of 'a' concatenated with 'a'
192+
193+
module.exports = function (a, b) {
194+
return a.length === b.length && (a + a).indexOf(b) > -1;
195+
};

0 commit comments

Comments
 (0)