-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathisPalindrome.js
50 lines (36 loc) · 1.14 KB
/
isPalindrome.js
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
Write a recursive function called isPalindrome
which returns true if the string passed to it is a palindrome (reads the same forward and backward).
Otherwise it returns false.
isPalindrome('awesome') // false
isPalindrome('foobar') // false
isPalindrome('tacocat') // true
isPalindrome('amanaplanacanalpanama') // true
isPalindrome('amanaplanacanalpandemonium') // false
*/
export function isPalindrome(string){
let og = string;
let reverseStr = ''
function reverse(str){
if (str.length === 0) return '';
let popped = str.substring(str.length - 1)
reverseStr += popped
return reverse(str.slice(0,-1))
}
reverse(string)
if (og === reverseStr) {
return true;
} else return false;
}
export function teejSol(str){
if (str.length <= 1) return true;
if (str[0] === str[str.length -1]){
return check(str.substring(1,-1))
} else return false;
}
export function isPalindromeSolution(str){
if(str.length === 1) return true;
if(str.length === 2) return str[0] === str[1];
if(str[0] === str.slice(-1)) return isPalindrome(str.slice(1,-1))
return false;
}