The Palindrome Test

by Eric Miller

JavaScript

/** ## Requirements ##

Input Validation:
The function should accept a single argument (usually a string) that represents the text to be tested.
Ensure that the input is a valid string (non-empty and containing alphanumeric characters).

Case Insensitivity:
The palindrome test should be case-insensitive. For example, “Racecar” and “racecar” should both be considered palindromes.

Whitespace and Punctuation Removal:
Remove any whitespace (spaces, tabs, etc.) and punctuation (commas, periods, etc.) from the input string before testing.
For instance, “A man, a plan, a canal: Panama” should be treated as “amanaplanacanalpanama”.

Character Comparison:
Compare characters from both ends of the modified string.
Start from the beginning and end of the string and check if the characters match.
Continue inward until the middle of the string is reached.

Palindrome Determination:
If all characters match (ignoring case and special characters), the input string is a palindrome.
Otherwise, it is not a palindrome.

Return Value:
The function should return a boolean value (true if the input is a palindrome, false otherwise).
*/

const testStrings = [
"A man, a plan, a canal: Panama",
"banana",
"Dad",
"Truck",
"12321",
];

function isPalindrome (input) {
	// Code Goes Here
}

testStrings.forEach((testString) => {
  console.log(`"${testString}" is a palindrome: ${isPalindrome(testString)}`);
});