Task: https://www.codewars.com/kata/54bb6f887e5a80180900046b/train/javascript
My solution:
function longestPalindrome(str){
var Palindromes = [], reverser = i => i.split("").reverse().join(""), l = str.length;
if (str === Infinity || str === -Infinity) {return 0}
else{
for (let i = l ; i >= 0; i--){
for(let j = 0; j < l; j++){
temp = str.slice(j, i)
if (reverser(temp) === temp){
Palindromes.push(temp)
}
}
}
return Math.max(...Palindromes.map(e => e.length));
}
}
My code works perfectly in my editor console, but when I submit it on codewars it says "-Infinity should return 0"? -Infinity returns 0 in other consoles however? Is there something wrong with my code? Please don't link to another question. I think my code works (?) except for a minor tweak somewhere.