Skip to content

Add palindrome utility function and corresponding tests#14

Open
callistoVII wants to merge 1 commit into
buwebdev:mainfrom
callistoVII:add_palindrome_function
Open

Add palindrome utility function and corresponding tests#14
callistoVII wants to merge 1 commit into
buwebdev:mainfrom
callistoVII:add_palindrome_function

Conversation

@callistoVII

Copy link
Copy Markdown

This Pull Request introduces a new utility function, isPalindrome, which determines whether a given string is a palindrome. This feature was implemented as part of Assignment 1.1, focusing on working within a feature branch, writing clean commits, and providing automated tests for validation.

The implementation includes:

A new utility file: src/utils/palindrome.js
A corresponding test suite: test/utils/palindrome.spec.js

The function normalizes input by lower-casing and removing non‑alphanumeric characters before performing the palindrome check. This ensures correct handling of mixed‑case strings, punctuation, and spacing.

No existing project files were modified.

Testing: Three unit tests were added to validate functionality.

Simple palindrome, verifies that a straightforward palindrome returns true.
Non-palindrome, ensures that a non-matching string returns false.
Punctuation/mixed-case palindrome, confirms correct behavior w/ normalized input.

To run test suite:
npm install
npm test

All tests pass successfully.

Note for Reviewers -
The feature is fully isolated to the add_palindrome_function branch. No changes were made to the project's main or existing utilities.

@slkueneke slkueneke left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Adding in comments would make the code a little clearer for someone updating, extending, or maintaining this function
  • Instead of returning false when the value passed is not a string, throw a descriptive error so the function's return value differentiates between passing a non-string value and a string that is not a palindrome (both currently return the same value of false).
  • It might be clearer to name the files (utility and corresponding tests) the same name as the function for quick finding and consistency.
  • Add in a 4th unit test for the use case when a non-string value is passed to the function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants