tests: pass palindromes

This commit is contained in:
abduldoesramen 2023-06-23 17:04:26 +10:00
parent 02a649e314
commit b5b3a35ff2
2 changed files with 28 additions and 8 deletions

View File

@ -1,5 +1,25 @@
const palindromes = function () { const palindromes = function (string) {
allLetters = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u",
"v", "w", "x", "y", "z", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0"]
normalString = Array.from(string.toLowerCase())
.filter(function (letter) {
return allLetters.includes(letter)
})
.join(",")
reverseString = Array.from(string.toLowerCase())
.filter(function (letter) {
return allLetters.includes(letter)
})
.reverse()
.join(",")
console.log(normalString)
console.log(reverseString)
return normalString === reverseString ? true : false
}; };
// Do not edit below this line // Do not edit below this line

View File

@ -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);
}); });
}); });