Merge pull request #8 from BillalPatel/palindrome

Fixed bug with code
This commit is contained in:
Billal Patel 2019-11-03 22:06:00 +00:00 committed by GitHub
commit 6cef4dc23b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 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;
} }
} }

View File

@ -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);
});
}); });