8000 Add solution for 09_palindromes · Boxis/javascript-exercises@142d8f8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 142d8f8

Browse files
committed
Add solution for 09_palindromes
1 parent b93897f commit 142d8f8

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

09_palindromes/palindromes.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
1-
const palindromes = function () {
1+
const palindromes = function (input) {
2+
// Remove punctuations
3+
const punctuationless = input.replace(/[.,\/#!$%\^&\*;:{}=\-_`~()]/g, "").toLowerCase();
24

5+
// Remove spaces
6+
const punctuationless1 = punctuationless.split(' ').join('');
7+
console.log(punctuationless1);
8+
for (let i = 0; i < punctuationless1.length/2; i++) {
9+
if (punctuationless1[i] != punctuationless1[punctuationless1.length - i - 1]) {
10+
return false;
11+
}
12+
}
13+
return true;
314
};
415

516
// Do not edit below this line

09_palindromes/palindromes.spec.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ describe('palindromes', () => {
44
test('works with single words', () => {
55
expect(palindromes('racecar')).toBe(true);
66
});
7-
test.skip('works with punctuation ', () => {
7+
test('works with punctuation ', () => {
88
expect(palindromes('racecar!')).toBe(true);
99
});
10-
test.skip('works with upper-case letters ', () => {
10+
test('works with upper-case letters ', () => {
1111
expect(palindromes('Racecar!')).toBe(true);
1212
});
13-
test.skip('works with multiple words', () => {
13+
test('works with multiple words', () => {
1414
expect(palindromes('A car, a man, a maraca.')).toBe(true);
1515
});
16-
test.skip('works with multiple words', () => {
16+
test('works with multiple words', () => {
1717
expect(palindromes('Animal loots foliated detail of stool lamina.')).toBe(true);
1818
});
19-
test.skip('doesn\'t just always return true', () => {
19+
test('doesn\'t just always return true', () => {
2020
expect(palindromes('ZZZZ car, a man, a maracaz.')).toBe(false);
2121
});
2222
});

0 commit comments

Comments
 (0)
0