My code is working perfectly and passing all test conditions. However, I am getting this error:
TypeError: unknown: Cannot read property ‘0’ of undefined
Could you please help me identifying the issue?
My code is here: https://codepen.io/farooqumars/pen/vVVJQR
Sounds like you are expecting something to be an array but in one or more test condition it is actually undefined
.
I am expecting that a string is provided for testing, not an array. But I convert that string to an array before parsing it.
I suspect that the problem is at line no.60:
> if(isNaN(Number.isInteger(parseInt(str[i]))))
Still I am unable to find the issue
You would get that error on that line if str
is undefined.
I removed these lines and it worked. Still not sure what was the cause but the problem is solved now.
for(var i=0; i<11; i++)
if(isNaN(Number.isInteger(parseInt(str[i])))) // if str has any non-number char
return false;