Skip to content

Latest commit

 

History

History
12 lines (10 loc) · 454 Bytes

File metadata and controls

12 lines (10 loc) · 454 Bytes

JavaScript - Chaining Array methods

Chaining the arrays methods will make our code to look prettier and less.

  • Example:
    • Find the total score of positive scores.
    const scores = [-1, 10, -20, 30, 100, 12, 132, -20, -90, 143, 68, -76];
    const positiveScoresSum  = scores.filter(score => score > 0)
                                     .reduce((sum, score) => sum += score, 0);
    console.log(positiveScoresSum);