Skip to content

Commit

Permalink
solve palindrome challenge
Browse files Browse the repository at this point in the history
  • Loading branch information
seunzone committed Mar 25, 2019
1 parent 9e73211 commit 6c44722
Show file tree
Hide file tree
Showing 5 changed files with 2,978 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
14 changes: 14 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "js-algorithms",
"version": "1.0.0",
"main": "index.js",
"repository": "https://github.com/seunzone/js-algorithms.git",
"author": "seunzone <darealseun@gmail.com>",
"scripts": {
"start": "jest palindrome/test.js"
},
"license": "MIT",
"dependencies": {
"jest": "^24.5.0"
}
}
10 changes: 10 additions & 0 deletions palindrome/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function palindrome(str) {
const myWord = str.split('').reverse().join('');
if (myWord == str){
return true
} else {
return false
}
}

module.exports = palindrome;
33 changes: 33 additions & 0 deletions palindrome/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const palindrome = require('./index');

test('palindrome function is defined', () => {
expect(typeof palindrome).toEqual('function');
});

test('"aba" is a palindrome', () => {
expect(palindrome('aba')).toBeTruthy();
});

test('" aba" is not a palindrome', () => {
expect(palindrome(' aba')).toBeFalsy();
});

test('"aba " is not a palindrome', () => {
expect(palindrome('aba ')).toBeFalsy();
});

test('"greetings" is not a palindrome', () => {
expect(palindrome('greetings')).toBeFalsy();
});

test('"1000000001" a palindrome', () => {
expect(palindrome('1000000001')).toBeTruthy();
});

test('"Fish hsif" is not a palindrome', () => {
expect(palindrome('Fish hsif')).toBeFalsy();
});

test('"pennep" a palindrome', () => {
expect(palindrome('pennep')).toBeTruthy();
});
Loading

0 comments on commit 6c44722

Please sign in to comment.