Fixed bug with code
This commit is contained in:
parent
75ae03bbc3
commit
92f305dac8
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue