Common algorithms

map()

map() applies a function to each value of a range and returns the results of applying that function.

map(["apple", "orange", "peach"], (item) => item.length)

filter()

filter() applies a predicate to each value of a range and filters out the values for which the predicate is false.

filter(["apple", "orange", "peach"], (item) => item.length == 5)

reduce()

reduce() combines the values of a range using a given function and returns a single value.

reduce(["apple", "orange", "peach"], "", (acc, item) => acc + item)

Get Programming with Types now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.