Hacker News new | past | comments | ask | show | jobs | submit login

because when you misscalculate the index, then it will not crash, but use the wrong one

I'm getting this right?




I don't understand why that would be more error prone than using list[list.length-1]. It's just list[-1].


imagine if you used list[index] where index would be calculated

if you misscalculated something and went on negative, then you'd have big exception/error, but when negative indices are viable, then the code will work fine




Consider applying for YC's W25 batch! Applications are open till Nov 12.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: