mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-19 10:05:41 +08:00
22 lines
414 B
JavaScript
22 lines
414 B
JavaScript
|
|
// Check whether the given string is Palindrome or not
|
|
export 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))
|
|
}
|
|
}
|