test 9 completed
This commit is contained in:
parent
8e3fa05fde
commit
799fe56a92
|
@ -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
|
// Do not edit below this line
|
||||||
|
|
|
@ -4,25 +4,25 @@ describe('palindromes', () => {
|
||||||
test('works with single words', () => {
|
test('works with single words', () => {
|
||||||
expect(palindromes('racecar')).toBe(true);
|
expect(palindromes('racecar')).toBe(true);
|
||||||
});
|
});
|
||||||
test.skip('works with punctuation ', () => {
|
test('works with punctuation ', () => {
|
||||||
expect(palindromes('racecar!')).toBe(true);
|
expect(palindromes('racecar!')).toBe(true);
|
||||||
});
|
});
|
||||||
test.skip('works with upper-case letters ', () => {
|
test('works with upper-case letters ', () => {
|
||||||
expect(palindromes('Racecar!')).toBe(true);
|
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);
|
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);
|
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);
|
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);
|
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);
|
expect(palindromes('r3ace3car')).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue