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
17 changes: 17 additions & 0 deletions src/utils/palindrome.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Author: Niki Nielsen
* Date: 06/03/2026
* File: palindrome.js
* Description: isPalindrome function.
*/

"use strict";

function isPalindrome(str) {
if (typeof str !== "string") return false;

const cleaned = str.toLowerCase().replace(/[^a-z0-9]/g, "");
return cleaned === cleaned.split("").reverse().join("");
}

module.exports = isPalindrome;
23 changes: 23 additions & 0 deletions test/utils/palindrome.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* Author: Niki Nielsen
* Date: 06/03/2026
* File: palindrome.spec.js
* Description: Tests for the isPalindrome function.
*/
"use strict";

const isPalindrome = require("../../src/utils/palindrome");

describe("palindrome.js", () => {
it("should return true for a simple palindrome", () => {
expect(isPalindrome("racecar")).toBe(true);
});

it("should return false for a non-palindrome", () => {
expect(isPalindrome("hello")).toBe(false);
});

it("should handle punctuation and mixed case", () => {
expect(isPalindrome("A man, a plan, a canal: Panama")).toBe(true);
});
});