forked from TheAlgorithms/JavaScript
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPalindrome.js
More file actions
Latest commit
25 lines (21 loc) · 533 Bytes
/
Copy pathPalindrome.js
File metadata and controls
25 lines (21 loc) · 533 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/**
* @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)
*/
constpalindrome=(str)=>{
if(typeofstr!=='string'){
thrownewTypeError('Invalid Input')
}
if(str.length<=1){
returntrue
}
if(str[0]!==str[str.length-1]){
returnfalse
}else{
returnpalindrome(str.slice(1,str.length-1))
}
}
export{palindrome}