File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change 1+
2+ // Check whether the given string is Palindrome or not
3+ const Palindrome = ( str ) => {
4+ if ( typeof str !== 'string' ) {
5+ str = str . toString ( )
6+ }
7+
8+ if ( str === null || str === undefined ) {
9+ return false
10+ }
11+
12+ if ( str . length === 1 || str . length === 0 ) {
13+ return true
14+ }
15+
16+ if ( str [ 0 ] !== str [ str . length - 1 ] ) {
17+ return false
18+ } else {
19+ return Palindrome ( str . slice ( 1 , str . length - 1 ) )
20+ }
21+ } ;
22+
23+ // testing
24+ ( ( ) => {
25+ console . log ( 'Palindrome: String: a = ' , Palindrome ( 'a' ) )
26+ console . log ( 'Palindrome: String: abba = ' , Palindrome ( 'abba' ) )
27+ console . log ( 'Palindrome: String: ababa = ' , Palindrome ( 'ababa' ) )
28+ console . log ( 'Not Palindrome: String: abbxa = ' , Palindrome ( 'abbxa' ) )
29+ console . log ( 'Not Palindrome: String: abxa = ' , Palindrome ( 'abxa' ) )
30+ } ) ( )
You can’t perform that action at this time.
0 commit comments