Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions Recursive/Palindrome.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

// Check whether the given string is Palindrome or not
const Palindrome = (str) => {
if (typeof str !== 'string') {
str = str.toString()
}

if (str === null || str === undefined) {
return false
}

if (str.length === 1 || str.length === 0) {
return true
}

if (str[0] !== str[str.length - 1]) {
return false
} else {
return Palindrome(str.slice(1, str.length - 1))
}
};

// testing
(() => {
console.log('Palindrome: String: a = ', Palindrome('a'))
console.log('Palindrome: String: abba = ', Palindrome('abba'))
console.log('Palindrome: String: ababa = ', Palindrome('ababa'))
console.log('Not Palindrome: String: abbxa = ', Palindrome('abbxa'))
console.log('Not Palindrome: String: abxa = ', Palindrome('abxa'))
})()