8000 palindrome solution · joshbjorn/javascript-exercises@956727d · GitHub
[go: up one dir, main page]

Skip to content

Commit 956727d

Browse files
committed
palindrome solution
1 parent d42eeba commit 956727d

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

palindromes/palindromes.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
var palindromes = function() {
1+
const palindromes = function(string) {
2+
processedString = string.toLowerCase().replace(/[^A-Za-z]/g, "");
3+
return (
4+
processedString
5+
.split("")
6+
.reverse()
7+
.join("") == processedString
8+
);
9+
};
210

3-
}
4-
5-
module.exports = palindromes
11+
module.exports = palindromes;

palindromes/palindromes.spec.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
1-
var palindromes = require('./palindromes')
1+
const palindromes = require("./palindromes");
22

3-
describe('palindromes', function() {
4-
it('works with single words', function() {
5-
expect(palindromes('racecar')).toEqual(true);
3+
describe("palindromes", () => {
4+
it("works with single words", () => {
5+
expect(palindromes("racecar")).toEqual(true);
66
});
7-
xit('works with punctuation', function() {
8-
expect(palindromes('Racecar!')).toEqual(true);
7+
it("works with punctuation", () => {
8+
expect(palindromes("Racecar!")).toEqual(true);
99
});
10-
xit('works with multiple words', function() {
11-
expect(palindromes('A car, a man, a maraca.')).toEqual(true);
10+
it("works with multiple words", () => {
11+
expect(palindromes("A car, a man, a maraca.")).toEqual(true);
1212
});
13-
xit('works with multiple words', function() {
14-
expect(palindromes('Animal loots foliated detail of stool lamina.')).toEqual(true);
13+
it("works with multiple words", () => {
14+
expect(
15+
palindromes("Animal loots foliated detail of stool lamina.")
16+
).toEqual(true);
1517
});
16-
xit('doesn\'t just always return true', function() {
17-
expect(palindromes('ZZZZ car, a man, a maraca.')).toEqual(false);
18+
it("doesn't just always return true", () => {
19+
expect(palindromes("ZZZZ car, a man, a maraca.")).toEqual(false);
1820
});
19-
2021
});

0 commit comments

Comments
 (0)
0