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
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
node_modules/
dist/
.env
.env.local
.env.*.local
*.log
.DS_Store
coverage/
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
# nodejs-practice-repository
# nodejs-practice-repository

A Node.js practice repo for learning JavaScript utilities and TDD.

## Getting Started

**Prerequisites:** Node.js and npm installed.

```bash
# Clone the repo
git clone https://github.com/jbb-codes/nodejs-practice-repository.git
cd nodejs-practice-repository

# Install dependencies
npm install

# Run tests
npm test
```
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.

17 changes: 17 additions & 0 deletions src/utils/reverseString.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Author: Jarren Bess
* Date: 2 June 2026
* File: reverseString.js
* Description: Utility function to reverse a string.
*/
"use strict";

function reverseString(str) {
if (typeof str !== "string") {
throw new Error("Input must be a string");
}

return str.split("").reverse().join("");
}

module.exports = { reverseString };
25 changes: 25 additions & 0 deletions test/utils/reverseString.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Author: Jarren Bess
* Date: 2 June 2026
* File: reverseString.spec.js
* Description: Tests for the reverseString utility function.
*/
"use strict";

const { reverseString } = require("../../src/utils/reverseString");

describe("reverseString", () => {
it("should reverse a regular string", () => {
const result = reverseString("hello");
expect(result).toBe("olleh");
});

it("should return an empty string when given an empty string", () => {
const result = reverseString("");
expect(result).toBe("");
});

it("should throw an error when given a non-string input", () => {
expect(() => reverseString(123)).toThrow("Input must be a string");
});
});