Tuesday, May 1, 2018

.reduce in TypeScript

This has this TypeScript example (complete with the missing let or const leading keyword) of making a mess based on all of the things in an array which gives us a six.

total = [0, 1, 2, 3].reduce((a, b) => a + b);
alert(total);

 
 

In JavaScript:

total = [0, 1, 2, 3].reduce(function (a, b) { return a + b; });
alert(total);

No comments:

Post a Comment