forked from TheAlgorithms/JavaScript
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckPalindrome.js
More file actions
Latest commit
17 lines (16 loc) · 602 Bytes
/
Copy pathCheckPalindrome.js
File metadata and controls
17 lines (16 loc) · 602 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// Palindrome check is case sensitive; i.e. Aba is not a palindrome
// input is a string
constcheckPalindrome=(str)=>{
// check that input is a string
if(typeofstr!=='string'){
return'Not a string'
}
if(str.length===0){
return'Empty string'
}
// Reverse only works with array, thus convert the string to array, reverse it and convert back to string
// return as palindrome if the reversed string is equal to the input string
constreversed=[...str].reverse().join('')
returnstr===reversed ? 'Palindrome' : 'Not a Palindrome'
}
export{checkPalindrome}