Files
JavaScript/Recursive/Palindrome.js
YATIN KATHURIA 6f1edd16f5 merge: Add test Case for Palindrome Recursive (#855)
* Add test Case for Palindrome Recursive

* Update Checks
2021-11-28 13:34:54 +05:30

26 lines
533 B
JavaScript

/**
* @function Palindrome
* @description Check whether the given string is Palindrome or not.
* @param {String} str - The input string
* @return {Boolean}.
* @see [Palindrome](https://en.wikipedia.org/wiki/Palindrome)
*/
const palindrome = (str) => {
if (typeof str !== 'string') {
throw new TypeError('Invalid Input')
}
if (str.length <= 1) {
return true
}
if (str[0] !== str[str.length - 1]) {
return false
} else {
return palindrome(str.slice(1, str.length - 1))
}
}
export { palindrome }