Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions solutions/120.js
Original file line number Diff line number Diff line change
@@ -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
};
11 changes: 11 additions & 0 deletions test/120.js
Original file line number Diff line number Diff line change
@@ -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);
});
});