diff --git a/solutions/120.js b/solutions/120.js new file mode 100644 index 0000000..a6b7d2c --- /dev/null +++ b/solutions/120.js @@ -0,0 +1,16 @@ +// check if arr is a palindrone +// daniel s. + +const solution = (arr) => { + if (arr.length <= 1) { + return true; + } + 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); + }); +});