commit
6cef4dc23b
|
@ -2,12 +2,13 @@ const palindromes = function(word) {
|
||||||
const wordArr = word.replace(/\W/g, '').toLowerCase().split('');
|
const wordArr = word.replace(/\W/g, '').toLowerCase().split('');
|
||||||
const reversedArr = wordArr.slice().reverse();
|
const reversedArr = wordArr.slice().reverse();
|
||||||
|
|
||||||
var status = false;
|
let status;
|
||||||
|
|
||||||
for (var i = 0; i < wordArr.length; i++) {
|
for (let i = 0; i < wordArr.length; i++) {
|
||||||
if (wordArr[i] === reversedArr[i]) {
|
if (wordArr[i] === reversedArr[i]) {
|
||||||
status = true;
|
status = true;
|
||||||
} else {
|
} else {
|
||||||
|
status = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,9 @@ const palindromes = require('./palindromes')
|
||||||
|
|
||||||
describe('palindromes', function() {
|
describe('palindromes', function() {
|
||||||
it('works with single words', function() {
|
it('works with single words', function() {
|
||||||
expect(palindromes('racecar')).toEqual(true);
|
expect(
|
||||||
|
palindromes('racecar')
|
||||||
|
).toEqual(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('works with punctuation', function() {
|
it('works with punctuation', function() {
|
||||||
|
@ -20,4 +22,8 @@ describe('palindromes', function() {
|
||||||
it('doesn\'t just always return true', function() {
|
it('doesn\'t just always return true', function() {
|
||||||
expect(palindromes('ZZZZ car, a man, a maraca.')).toEqual(false);
|
expect(palindromes('ZZZZ car, a man, a maraca.')).toEqual(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Not matching letters can be in the middle and still fail', function() {
|
||||||
|
expect(palindromes('A car, Zzz a man, a maraca.')).toEqual(false);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue