Fixed bug with code

This commit is contained in:
billalp 2019-11-03 21:53:12 +00:00
parent 75ae03bbc3
commit 92f305dac8
2 changed files with 10 additions and 3 deletions

View File

@ -2,12 +2,13 @@ const palindromes = function(word) {
const wordArr = word.replace(/\W/g, '').toLowerCase().split('');
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]) {
status = true;
} else {
status = false;
break;
}
}

View File

@ -2,7 +2,9 @@ const palindromes = require('./palindromes')
describe('palindromes', function() {
it('works with single words', function() {
expect(palindromes('racecar')).toEqual(true);
expect(
palindromes('racecar')
).toEqual(true);
});
it('works with punctuation', function() {
@ -20,4 +22,8 @@ describe('palindromes', function() {
it('doesn\'t just always return true', function() {
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);
});
});