From ccf4400fa9f4c634f25517cc790d964c6dcbde63 Mon Sep 17 00:00:00 2001 From: Shirley Fang Date: Sat, 14 Oct 2023 10:49:12 -0400 Subject: [PATCH] Added temporary placeholder test --- palindrome.test.ts | 13 +++++++++++++ palindrome.ts | 5 +++++ 2 files changed, 18 insertions(+) create mode 100644 palindrome.test.ts create mode 100644 palindrome.ts diff --git a/palindrome.test.ts b/palindrome.test.ts new file mode 100644 index 0000000..3448525 --- /dev/null +++ b/palindrome.test.ts @@ -0,0 +1,13 @@ +import { isPalindrome } from './palindrome'; + +describe('isPalindrome', () => { + it('should return true for palindromic strings', () => { + expect(isPalindrome('radar')).toBe(true); + expect(isPalindrome('A man, a plan, a canal, Panama!')).toBe(true); + }); + + it('should return false for non-palindromic strings', () => { + expect(isPalindrome('hello')).toBe(false); + expect(isPalindrome('OpenAI')).toBe(false); + }); +}); diff --git a/palindrome.ts b/palindrome.ts new file mode 100644 index 0000000..1db029a --- /dev/null +++ b/palindrome.ts @@ -0,0 +1,5 @@ +export const isPalindrome = (s: string): boolean => { + const cleanedString = s.replace(/[^A-Za-z0-9]/g, '').toLowerCase(); + const reversedString = cleanedString.split('').reverse().join(''); + return cleanedString === reversedString; +};