Skip to content

Commit

Permalink
fix: update palindrome checker to work with phrases
Browse files Browse the repository at this point in the history
  • Loading branch information
scissorsneedfoodtoo committed Nov 20, 2023
1 parent a64c4d3 commit ee98f03
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions apps/palindrome-checker/public/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ const checkPalindromeBtn = document.getElementById('btn');
const resultDiv = document.getElementById('result');

const checkForPalindrome = input => {
const hasSpecialCharactersOrDigits = /[\W\d_]/.test(input);
const originalInput = input; // Store for later output
const hasSpecialCharactersOrDigits = /[\W\d_]/.test(input.replace(/\s/g, '')); // Remove whitespace before checking for special characters and digits

if (input === '') {
alert('Please input a value');
Expand All @@ -18,7 +19,7 @@ const checkForPalindrome = input => {
resultDiv.replaceChildren();

const lowerCaseStr = input.replace(/[^A-Z0-9]/gi, '').toLowerCase();
let resultMsg = `${input} ${
let resultMsg = `${originalInput} ${
lowerCaseStr === [...lowerCaseStr].reverse().join('') ? 'is' : 'is not'
} a palindrome.`;

Expand Down

0 comments on commit ee98f03

Please sign in to comment.