From 0693498128efdcab014f2ff300ba3d00c2228080 Mon Sep 17 00:00:00 2001 From: Ocn <ocnly@users.noreply.github.com> Date: Thu, 20 Sep 2018 02:48:12 +0400 Subject: [PATCH 1/6] Check for palindromes --- src/algorithms/string/palindrome/palindrome.js | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/algorithms/string/palindrome/palindrome.js diff --git a/src/algorithms/string/palindrome/palindrome.js b/src/algorithms/string/palindrome/palindrome.js new file mode 100644 index 0000000000..08b91fd5d9 --- /dev/null +++ b/src/algorithms/string/palindrome/palindrome.js @@ -0,0 +1,8 @@ +/** + * @param {string} string + * @return {boolean} + */ +export default function palindrome(string) { + reverseString = string.split("").reverse().join(""); + return reverseString === string; +} From 31622e2bdfc98bdf9d889c11471f9a5c9a97c764 Mon Sep 17 00:00:00 2001 From: Ocn <ocnly@users.noreply.github.com> Date: Thu, 20 Sep 2018 03:14:35 +0400 Subject: [PATCH 2/6] Add test for palindrome() --- .../string/palindrome/__true__/palindrome.test.js | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/algorithms/string/palindrome/__true__/palindrome.test.js diff --git a/src/algorithms/string/palindrome/__true__/palindrome.test.js b/src/algorithms/string/palindrome/__true__/palindrome.test.js new file mode 100644 index 0000000000..04ae179d34 --- /dev/null +++ b/src/algorithms/string/palindrome/__true__/palindrome.test.js @@ -0,0 +1,8 @@ +import palindrome from '../palindrome'; + +describe('palindrome', () => { + it('should return true if word is a palindrome', () => { + expect(palindrome('racecar').toBe(true); + expect(palindrome('car').toBe(false); + } +} From 47f22f57f380c58efd140ffc68b04933ba2c084d Mon Sep 17 00:00:00 2001 From: Ocn <ocnly@users.noreply.github.com> Date: Thu, 20 Sep 2018 03:22:14 +0400 Subject: [PATCH 3/6] Add README --- src/algorithms/string/palindrome/README.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 src/algorithms/string/palindrome/README.md diff --git a/src/algorithms/string/palindrome/README.md b/src/algorithms/string/palindrome/README.md new file mode 100644 index 0000000000..c9d774b05e --- /dev/null +++ b/src/algorithms/string/palindrome/README.md @@ -0,0 +1 @@ +This is a *WIP*. From 0a8c56a35f4231473beda0a423e578295afa34b4 Mon Sep 17 00:00:00 2001 From: Ocn <ocnly@users.noreply.github.com> Date: Thu, 20 Sep 2018 06:15:39 +0400 Subject: [PATCH 4/6] Fix errors --- src/algorithms/string/palindrome/__true__/palindrome.test.js | 4 ++-- src/algorithms/string/palindrome/palindrome.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/algorithms/string/palindrome/__true__/palindrome.test.js b/src/algorithms/string/palindrome/__true__/palindrome.test.js index 04ae179d34..6b458eb59d 100644 --- a/src/algorithms/string/palindrome/__true__/palindrome.test.js +++ b/src/algorithms/string/palindrome/__true__/palindrome.test.js @@ -2,7 +2,7 @@ import palindrome from '../palindrome'; describe('palindrome', () => { it('should return true if word is a palindrome', () => { - expect(palindrome('racecar').toBe(true); - expect(palindrome('car').toBe(false); + expect(palindrome('racecar')).toBe(true); + expect(palindrome('car')).toBe(false); } } diff --git a/src/algorithms/string/palindrome/palindrome.js b/src/algorithms/string/palindrome/palindrome.js index 08b91fd5d9..9d0d9ea13f 100644 --- a/src/algorithms/string/palindrome/palindrome.js +++ b/src/algorithms/string/palindrome/palindrome.js @@ -3,6 +3,6 @@ * @return {boolean} */ export default function palindrome(string) { - reverseString = string.split("").reverse().join(""); + const reverseString = string.split('').reverse().join(''); return reverseString === string; } From 80e160e7a3b1ca7e080147d367b20f5aa3ed3cfd Mon Sep 17 00:00:00 2001 From: Ocn <ocnly@users.noreply.github.com> Date: Thu, 20 Sep 2018 06:39:11 +0400 Subject: [PATCH 5/6] Fix one more error --- src/algorithms/string/palindrome/__true__/palindrome.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/algorithms/string/palindrome/__true__/palindrome.test.js b/src/algorithms/string/palindrome/__true__/palindrome.test.js index 6b458eb59d..edc0f0ac22 100644 --- a/src/algorithms/string/palindrome/__true__/palindrome.test.js +++ b/src/algorithms/string/palindrome/__true__/palindrome.test.js @@ -4,5 +4,5 @@ describe('palindrome', () => { it('should return true if word is a palindrome', () => { expect(palindrome('racecar')).toBe(true); expect(palindrome('car')).toBe(false); - } + }); } From 09b53c0d79aa9b5a66d4d55867d22d12c98700d2 Mon Sep 17 00:00:00 2001 From: Ocn <ocnly@users.noreply.github.com> Date: Thu, 20 Sep 2018 06:43:03 +0400 Subject: [PATCH 6/6] Fix error --- src/algorithms/string/palindrome/__true__/palindrome.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/algorithms/string/palindrome/__true__/palindrome.test.js b/src/algorithms/string/palindrome/__true__/palindrome.test.js index edc0f0ac22..d04a334a9c 100644 --- a/src/algorithms/string/palindrome/__true__/palindrome.test.js +++ b/src/algorithms/string/palindrome/__true__/palindrome.test.js @@ -5,4 +5,4 @@ describe('palindrome', () => { expect(palindrome('racecar')).toBe(true); expect(palindrome('car')).toBe(false); }); -} +});