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'
31
31
import swapCase from './swap-case'
32
32
import endsWith from './endsWith'
33
33
import round from './round'
34
+ import checkPalindrome from './checkPalindrome'
34
35
35
36
export {
36
37
initArray ,
@@ -66,4 +67,5 @@ export {
66
67
swapCase ,
67
68
endsWith ,
68
69
round ,
70
+ checkPalindrome ,
69
71
}
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