8000 Finished palindromes exercise · JonathanYiv/javascript-exercises@3c012a8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3c012a8

Browse files
committed
Finished palindromes exercise
1 parent 0a449a9 commit 3c012a8

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

palindromes/palindromes.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
var palindromes = function() {
2-
1+
var palindromes = function(text) {
2+
const regex = new RegExp(/[!,\.\s]/, 'g');
3+
const strippedText = text.toLowerCase().replace(regex, "");
4+
const reversedText = strippedText.split("").reverse().join("");
5+
return reversedText === strippedText ? true : false;
36
}
47

58
module.exports = palindromes

palindromes/palindromes.spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ describe('palindromes', function() {
44
it('works with single words', function() {
55
expect(palindromes('racecar')).toEqual(true);
66
});
7-
xit('works with punctuation', function() {
7+
it('works with punctuation', function() {
88
expect(palindromes('Racecar!')).toEqual(true);
99
});
10-
xit('works with multiple words', function() {
10+
it('works with multiple words', function() {
1111
expect(palindromes('A car, a man, a maraca.')).toEqual(true);
1212
});
13-
xit('works with multiple words', function() {
13+
it('works with multiple words', function() {
1414
expect(palindromes('Animal loots foliated detail of stool lamina.')).toEqual(true);
1515
});
16-
xit('doesn\'t just always return true', function() {
16+
it('doesn\'t just always return true', function() {
1717
expect(palindromes('ZZZZ car, a man, a maraca.')).toEqual(false);
1818
});
1919

0 commit comments

Comments
 (0)
0