Echo JS 0.11.0

<~>
tracker1 2856 days ago. link 1 point
Two things I always try to enforce in code reviews are the use of map/reduce instead of for-loops when practical, and returning early from functions...

    // instead of
    fn() {
      if (foo) {
        //really long code block
      } else {
        //really short code block
      }
    }

    // this
    fn() {
      if (!foo) {
        // really short code block
        return ...;
      }

      // less nested code case
    }

It tends to happen a lot, and the function becomes much more clear when you can get out of it asap instead of deep nested blocks.

Replies

xab 2856 days ago. link 2 points
Exactly. Deep indentation pyramids are evil, but the pluck in the article is such a bad example. Pluck? How about a simple map? `myArray.map(item => item.id)` Map, reduce, Object.keys and forEach, a one liner range, [...new Set([])] uniques, so many wonderful things readily available with babel and friends :) Anonther favorite of mine is the async/yield pair, can make promise chains so much nicer!