This repository was archived by the owner on Feb 20, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +37
-0
lines changed Expand file tree Collapse file tree 3 files changed +37
-0
lines changed Original file line number Diff line number Diff line change 1+ export default checkPalindrome
2+
3+ /**
4+ *Original Source: https://stackoverflow.com/questions/41739845/freecodecamp-checking-for-palindromes
5+ *This method will check to see if
6+ *after removing all non alphanumeric characters,
7+ *the string is a palindrome
8+ * @param {String } str - string to check for Palindrome
9+ * @return {Boolean } - should return true or false
10+ */
11+
12+ function checkPalindrome ( str ) {
13+ const newstr = str . replace ( / [ \W _ ] / g, '' ) . toLowerCase ( )
14+
15+ if ( newstr === newstr . split ( '' ) . reverse ( ) . join ( '' ) ) {
16+ return true
17+ }
18+ return false
19+ }
Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ import shallowEqual from './shallow-equal'
3131import swapCase from './swap-case'
3232import endsWith from './endsWith'
3333import round from './round'
34+ import checkPalindrome from './checkPalindrome'
3435
3536export {
3637 initArray ,
@@ -66,4 +67,5 @@ export {
6667 swapCase ,
6768 endsWith ,
6869 round ,
70+ checkPalindrome ,
6971}
Original file line number Diff line number Diff line change 1+ import test from 'ava'
2+ import { checkPalindrome } from '../src'
3+
4+ test ( 'string is not a palindrome' , t => {
5+ const object = 'hello world'
6+ const expected = false
7+ const actual = checkPalindrome ( object )
8+ t . deepEqual ( actual , expected )
9+ } )
10+
11+ test ( ' string is a palindrome' , t => {
12+ const object = 'l/o1&&9_J$$J 9!1ol'
13+ const expected = true
14+ const actual = checkPalindrome ( object )
15+ t . deepEqual ( actual , expected )
16+ } )
You can’t perform that action at this time.
0 commit comments