Skip to content

Commit 295429c

Browse files
authored
Create palindrome.js
1 parent 9bfd527 commit 295429c

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

palindrome.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// filename: palindrome.js
2+
// Run: node palindrome.js racecar
3+
const input = process.argv[2];
4+
if (!input) {
5+
console.log("Usage: node palindrome.js <string>");
6+
process.exit(1);
7+
}
8+
function isPalindrome(str) {
9+
const cleaned = str.toLowerCase().replace(/[^a-z0-9]/g, "");
10+
return cleaned === cleaned.split("").reverse().join("");
11+
}
12+
console.log(`${input}${isPalindrome(input) ? "Palindrome" : "Not Palindrome"}`);

0 commit comments

Comments
 (0)