Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Node dependencies
node_modules/

# Logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*

# Environment files
.env
.env.local
.env.*.local

# OS files
.DS_Store
Thumbs.db

# Editor / IDE settings
.vscode/
.idea/

# Coverage reports
coverage/

# Build output (if applicable)
dist/
build/
39 changes: 38 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,38 @@
# nodejs-practice-repository
# Node.js Practice Repository

This repository contains small Node.js utility functions with automated unit tests.
Each feature is developed on its own branch and submitted via a Pull Request.

---

## Palindrome Function

### Description

Adds a utility function that checks whether a given string is a palindrome.
The function ignores spaces, punctuation, and letter casing.

Example:

- `"racecar"` → `true`
- `"A man a plan a canal Panama"` → `true`
- `"hello"` → `false`

---

## Setup Instructions

### Prerequisites

- Node.js (LTS version recommended)
- npm (included with Node.js)

### Install Dependencies

Clone the repository and install dependencies:

```bash
git clone https://github.com/tink012184/nodejs-practice-repository.git
cd nodejs-practice-repository
npm install
```
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions src/palindrome.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Checks if a string is a palindrome.
* Ignores spaces, punctuation, and letter casing.
*
* @param {string} input
* @returns {boolean}
*/
function isPalindrome(input) {
if (typeof input !== "string") {
return false;
}

const cleaned = input.toLowerCase().replace(/[^a-z0-9]/g, "");

const reversed = cleaned.split("").reverse().join("");

return cleaned === reversed;
}

module.exports = { isPalindrome };
15 changes: 15 additions & 0 deletions test/palindrome.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const { isPalindrome } = require("../src/palindrome");

describe("isPalindrome", () => {
test("returns true for a simple palindrome", () => {
expect(isPalindrome("racecar")).toBe(true);
});

test("returns true for a palindrome with spaces and capitalization", () => {
expect(isPalindrome("A man a plan a canal Panama")).toBe(true);
});

test("returns false for a non-palindrome string", () => {
expect(isPalindrome("hello world")).toBe(false);
});
});