Skip to content

Commit 04d22ac

Browse files
author
wakidurrahman
committed
feat: added
1 parent b2e76f5 commit 04d22ac

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,14 @@ exports.iterative = function (array) {
182182
};
183183

184184
/**
185-
* Q007: Sum of Array Plus One
186-
*
187-
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'
188188
*/
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)