MCPcopy Create free account
hub / github.com/TheAlgorithms/JavaScript / palindrome

Function palindrome

Recursive/Palindrome.js:9–23  ·  view source on GitHub ↗
(str)

Source from the content-addressed store, hash-verified

7 */
8
9const palindrome = (str) => {
10 if (typeof str !== 'string') {
11 throw new TypeError('Invalid Input')
12 }
13
14 if (str.length <= 1) {
15 return true
16 }
17
18 if (str[0] !== str[str.length - 1]) {
19 return false
20 } else {
21 return palindrome(str.slice(1, str.length - 1))
22 }
23}
24
25export { palindrome }

Callers 2

backtrackFunction · 0.90
Palindrome.test.jsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected