From 799fe56a92cbb3b08d5dd6f714619611b44a43df Mon Sep 17 00:00:00 2001 From: rajroushan6714 Date: Fri, 25 Aug 2023 11:02:55 +0530 Subject: [PATCH] test 9 completed --- 09_palindromes/palindromes.js | 17 ++++++++++++++++- 09_palindromes/palindromes.spec.js | 14 +++++++------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/09_palindromes/palindromes.js b/09_palindromes/palindromes.js index 8d21018..e9212ef 100644 --- a/09_palindromes/palindromes.js +++ b/09_palindromes/palindromes.js @@ -1,5 +1,20 @@ -const palindromes = function () { +const palindromes = function (string) { + // replace(str1 , str2) replaces all str1 with str2. + let processedString = string.toLowerCase().replace(/[^a-z0-9]/g,""); + return processedString == processedString.split('').reverse().join(''); + // Solution 2 : + + // let str = string.toLowerCase(); + // let myArray = str.split(''); + // let temp = ""; + // let n = myArray.length; + // for(let i = 0 ;i < n ;i++){ + // if(myArray[i]>= 'a' && myArray[i] <= 'z' || myArray[i] <= '9' && myArray[i] >= '0'){ + // temp += myArray[i]; + // } + // } + // return temp == temp.split('').reverse().join(''); }; // Do not edit below this line diff --git a/09_palindromes/palindromes.spec.js b/09_palindromes/palindromes.spec.js index 90d53e4..8ce5aac 100644 --- a/09_palindromes/palindromes.spec.js +++ b/09_palindromes/palindromes.spec.js @@ -4,25 +4,25 @@ describe('palindromes', () => { test('works with single words', () => { expect(palindromes('racecar')).toBe(true); }); - test.skip('works with punctuation ', () => { + test('works with punctuation ', () => { expect(palindromes('racecar!')).toBe(true); }); - test.skip('works with upper-case letters ', () => { + test('works with upper-case letters ', () => { expect(palindromes('Racecar!')).toBe(true); }); - test.skip('works with multiple words', () => { + test('works with multiple words', () => { expect(palindromes('A car, a man, a maraca.')).toBe(true); }); - test.skip('works with multiple words', () => { + test('works with multiple words', () => { expect(palindromes('Animal loots foliated detail of stool lamina.')).toBe(true); }); - test.skip('doesn\'t just always return true', () => { + test('doesn\'t just always return true', () => { expect(palindromes('ZZZZ car, a man, a maracaz.')).toBe(false); }); - test.skip('works with numbers in a string', () => { + test('works with numbers in a string', () => { expect(palindromes('rac3e3car')).toBe(true); }); - test.skip('works with unevenly spaced numbers in a string', () => { + test('works with unevenly spaced numbers in a string', () => { expect(palindromes('r3ace3car')).toBe(false); }); });