GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — palindrome-recursive-algorithm-added (#450) · Randomlyclueless/JavaScript@bc76dad

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • Recursive
    • Palindrome.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎Recursive/Palindrome.js‎

Copy file name to clipboard
+30Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
// Check whether the given string is Palindrome or not
3+
const Palindrome = (str) => {
4+
if (typeof str !== 'string') {
5+
str = str.toString()
6+
}
7+
8+
if (str === null || str === undefined) {
9+
return false
10+
}
11+
12+
if (str.length === 1 || str.length === 0) {
13+
return true
14+
}
15+
16+
if (str[0] !== str[str.length - 1]) {
17+
return false
18+
} else {
19+
return Palindrome(str.slice(1, str.length - 1))
20+
}
21+
};
22+
23+
// testing
24+
(() => {
25+
console.log('Palindrome: String: a = ', Palindrome('a'))
26+
console.log('Palindrome: String: abba = ', Palindrome('abba'))
27+
console.log('Palindrome: String: ababa = ', Palindrome('ababa'))
28+
console.log('Not Palindrome: String: abbxa = ', Palindrome('abbxa'))
29+
console.log('Not Palindrome: String: abxa = ', Palindrome('abxa'))
30+
})()

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.