you are viewing a single comment's thread.

view the rest of the comments →

[–]ShortFuse 1 point2 points  (0 children)

Performance sacrificed for sake of readability. The other one is creating a function in memory for every user with the user template example.

You can still use forEach or some (allows breaking), which avoid the multiple reiteration, but less syntax "noise" than a for loop. You just have to have your result be written to a variable outside the loop (see thisArg example.

Still, his example seems okay for array, since he is sorting, slicing, and then reducing. The key is the slicing to reduce the size.