Skip to content

Commit 8d2bc37

Browse files
Merge pull request #107 from entonibaba0720/entonibaba0720
added recursive palindrome algo
2 parents 4974a50 + 23461d9 commit 8d2bc37

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
function recursivePalindrome(str) {
2+
if (typeof str === "string" || typeof str === "number") {
3+
str = str + "";
4+
5+
if (str.length <= 1) {
6+
return true;
7+
}
8+
9+
if (str[0] === str[str.length - 1]) {
10+
return recursivePalindrome(str.substr(1, str.length - 2));
11+
}
12+
}
13+
return false;
14+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
### What is a palindrome?
2+
3+
A palindrome is a word that is spelled the same forward and backward. For example, rotor is a palindrome, but motor is not.
4+
5+
### What is Recursion?
6+
7+
The process in which a function calls itself directly or indirectly is called recursion and the corresponding function is called as recursive function.

0 commit comments

Comments
 (0)