Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

if order does not matter:

var sum=0,i=list.length; while(i--) sum += list[i].amount;

if it does: var sum=0,i=0,ln=list.length; while (ln-- && (sum += list[i++].amount));

but the for in syntax is nicer indeed.



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

Search: