Hello! I was solving this task and suddenly my code sometimes works well and sometimes not. I can’t find the reason. Help me please. Here is my code.
P.S. I haven’t looked at the solution.
P.P.S. I know I should have named variables more clear and created a new function for the nested foor loop.
Your code so far
function palindrome(str) {
var letter = ['a', 'b', 'c', 'd', 'e', 'f', 'g',
'h', 'i', 'j', 'k', 'l', 'm', 'n',
'o', 'p', 'q', 'r', 's', 't', 'u',
'v', 'w', 'x', 'y', 'z'
];//characters a palindrome can contain
var arrStr = [];//array for str
var strReversed = [];//array for reversed str
str.toLowerCase();
arrStr = str.split("");
for(var i = 0; i < arrStr; i++)
for(var j = 0; j < word.length; j++)
if(arrStr[i] == letter[j])//check if it isn't a letter
delete arrStr[i];//if so, delete the element
strReversed = arrStr;//now we can see if there's
strReversed.reverse();//a difference between them
for(var k = 0; k < arrStr.length; k++)
if(arrStr[k] != strReversed[k])//once we find some characters do not match
return false;//it means str isn't a palindrome
return true;
}
palindrome("eye");
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:56.0) Gecko/20100101 Firefox/56.0
.
Link to the challenge: