From 7d84e6c17fc13bb84aedb4277945e32625458748 Mon Sep 17 00:00:00 2001 From: ErnestoXG Date: Thu, 16 Feb 2023 20:38:09 +0000 Subject: [PATCH 1/3] added solution for geeksforgeeks --- exercises/153-isRotated/solution.hide.js | 30 ++++++++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/exercises/153-isRotated/solution.hide.js b/exercises/153-isRotated/solution.hide.js index 908d49865..5e416d566 100644 --- a/exercises/153-isRotated/solution.hide.js +++ b/exercises/153-isRotated/solution.hide.js @@ -1,11 +1,31 @@ +// NOTE for further explantion of this solution visit: https://www.geeksforgeeks.org/a-program-to-check-if-strings-are-rotations-of-each-other/ function isRotated(str1, str2) { // your code here - let fracc = str1.split(''); - let aux = []; - for (let i of fracc) aux.push(str2.indexOf(i)); - let result = !aux.includes(-1); - return result; + if (str1.length != str2.length) { + return false; + } + + let q1 = [] + for (let i = 0; i < str1.length; i++) + q1.push(str1[i]) + + let q2 = [] + for (let i = 0; i < str2.length; i++) + q2.push(str2[i]) + + let k = str2.length + + while (k--) { + let ch = q2[0] + q2.shift() + q2.push(ch) + if (JSON.stringify(q2) == JSON.stringify(q1)) + return true + } + + return false } console.log(isRotated('hello world', 'orldhello w')); // => true console.log(isRotated('hello world', 'omrel wp')); // => false + From 03b849f30919209b6dcf6d4b681a6fdd205c11a2 Mon Sep 17 00:00:00 2001 From: ErnestoXG Date: Thu, 16 Feb 2023 20:38:22 +0000 Subject: [PATCH 2/3] fixed tests looking for the wrong results --- exercises/153-isRotated/test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exercises/153-isRotated/test.js b/exercises/153-isRotated/test.js index 9afcfac02..51ff6b160 100644 --- a/exercises/153-isRotated/test.js +++ b/exercises/153-isRotated/test.js @@ -22,9 +22,9 @@ test('The function should return true or false if there is one of the 2 given st }); test('The function should return true or false if there is one of the 2 given strings rotated.', () => { - expect(isRotated('Learning is fun', 'Lr aen ngiiufs')).toBe(true); + expect(isRotated('Learning is fun', 'Lr aen ngiiufs')).toBe(false); }); test('The function should return true or false if there is one of the 2 given strings rotated.', () => { - expect(isRotated('Work from Home', 'kfmoemro Hor W')).toBe(true); + expect(isRotated('Work from Home', ' HomeWork from')).toBe(true); }); From d2bb3a99faf47ffaad60285b0d950d0f76b049c4 Mon Sep 17 00:00:00 2001 From: ErnestoXG Date: Thu, 16 Feb 2023 20:45:21 +0000 Subject: [PATCH 3/3] added documentation --- exercises/153-isRotated/README.es.md | 1 + exercises/153-isRotated/README.md | 2 ++ 2 files changed, 3 insertions(+) diff --git a/exercises/153-isRotated/README.es.md b/exercises/153-isRotated/README.es.md index 48329ce02..62c93b973 100644 --- a/exercises/153-isRotated/README.es.md +++ b/exercises/153-isRotated/README.es.md @@ -12,3 +12,4 @@ Una rotación en una cadena se define como quitar el primer elemento y concatena let output = isRotated("Hello World", "orldHello W") console.log(output) // true ``` +> Más informacion acerca de la rotación de cadenas: [click aquí](https://www.techiedelight.com/es/find-lexicographically-minimal-string-rotation/) \ No newline at end of file diff --git a/exercises/153-isRotated/README.md b/exercises/153-isRotated/README.md index 9de64815c..fd9605714 100644 --- a/exercises/153-isRotated/README.md +++ b/exercises/153-isRotated/README.md @@ -12,3 +12,5 @@ A rotation on a string is defined as removing first element and concatenating it let output = isRotated("Hello World", "orldHello W") console.log(output) // true ``` + +> For better understanding of string rotation check this article: [click me](https://javarevisited.blogspot.com/2017/07/2-ways-to-check-if-one-string-is-rotation-of-another-String.html#axzz7tVz1WCRT)