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

> list.reduce((x,y)=>Math.max(x,y))

Honestly, while I like the clarity, I would still dislike it in JavaScript for performance reasons, because in JavaScript reduce is not optimized at all. And yes, I do work on a code-base where that difference is significant.

Also, that loop can still be cleaned up a bit in modern JS:

    let max = list[0];
    for (const v of list) {
      if (v > max) max = v;
    }


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

Search: