From 92f305dac8364b42239acf392f47827e49f5963a Mon Sep 17 00:00:00 2001 From: billalp Date: Sun, 3 Nov 2019 21:53:12 +0000 Subject: [PATCH] Fixed bug with code --- palindromes/palindromes.js | 5 +++-- palindromes/palindromes.spec.js | 8 +++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/palindromes/palindromes.js b/palindromes/palindromes.js index 607fe3e..4d1c98c 100644 --- a/palindromes/palindromes.js +++ b/palindromes/palindromes.js @@ -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; } } diff --git a/palindromes/palindromes.spec.js b/palindromes/palindromes.spec.js index 4a4b820..a6d423f 100644 --- a/palindromes/palindromes.spec.js +++ b/palindromes/palindromes.spec.js @@ -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); + }); });