From cef8c764f105027dd1929bf59e41f2ab8a4c4d52 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 14 Aug 2017 13:44:43 -0700 Subject: [PATCH 1/2] solution for issue 120 --- solutions/120.js | 17 +++++++++++++++++ test/120.js | 11 +++++++++++ 2 files changed, 28 insertions(+) create mode 100644 solutions/120.js create mode 100644 test/120.js diff --git a/solutions/120.js b/solutions/120.js new file mode 100644 index 0000000..c9d8df5 --- /dev/null +++ b/solutions/120.js @@ -0,0 +1,17 @@ +// check if arr is a palindrone +// daniel s. + +const solution = (arr) => { + if (arr.length <= 1) { + return true; + } + console.log('ar', arr); + if (arr.pop() === arr.shift()) { + return solution(arr); + } + return false; +}; + +module.exports = { + solution: solution +}; diff --git a/test/120.js b/test/120.js new file mode 100644 index 0000000..cc4318e --- /dev/null +++ b/test/120.js @@ -0,0 +1,11 @@ +const expect = require('chai').expect; +let solution = require('../solutions/120').solution; + +describe('reverse array', () => { + it('should return true if input string is a palindrome', () => { + expect(solution(['r', 'a', 'c', 'e', 'c', 'a', 'r'])).to.equal(true); + }); + it('should return true if input string is a palindrome', () => { + expect(solution(['h', 'w', 'e', 's', 'u'])).to.equal(false); + }); +}); From 792de61a649a3bea381981caddb6e0c0f90c2ebc Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 14 Aug 2017 13:46:49 -0700 Subject: [PATCH 2/2] remove console log --- solutions/120.js | 1 - 1 file changed, 1 deletion(-) diff --git a/solutions/120.js b/solutions/120.js index c9d8df5..a6b7d2c 100644 --- a/solutions/120.js +++ b/solutions/120.js @@ -5,7 +5,6 @@ const solution = (arr) => { if (arr.length <= 1) { return true; } - console.log('ar', arr); if (arr.pop() === arr.shift()) { return solution(arr); }