Created
April 26, 2019 20:36
-
-
Save emmsdan/15b12ddc2582a314742b7b0ba4fad486 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const palindrome = (words) => { | |
| if (typeof words !== 'string') return 'provide a string or a phrase'; | |
| const wordArray = words.replace(/([^\w])/g, '').split(''); | |
| return checkPalindrome(wordArray); | |
| } | |
| function checkPalindrome(arrayOfChars) { | |
| if (!Array.isArray(arrayOfChars)) return 'please provide an array'; | |
| if (arrayOfChars.join('') === arrayOfChars.reverse().join('')) return 'this is a palindrome'; | |
| return 'this is not a palindrome'; | |
| } | |
| console.log('fail: ', palindrome([])); | |
| console.log('fail: ', palindrome(12)); | |
| console.log('fail: ', palindrome('12')); | |
| console.log('fail: ', palindrome('popp')); | |
| console.log('pass: ', palindrome('madam')); | |
| console.log('pass: ', palindrome('pop')); | |
| console.log('pass: ', palindrome('nurses run')); | |
| console.log('pass: ', palindrome('peep')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment