Array Pipes — JavaScript

Pipe data through array methods: 15 levels chaining map, filter and reduce. The densest JavaScript functional programming game for arrays.

What you learn in this game

.map() makes a new array by applying a function to each element. The original array doesn't change.

.filter() makes a new array containing only the elements that pass the condition (the callback returns true).

.reduce() accumulates all the array elements into a single value. It takes a callback(accumulator, currentValue) and an initial value.

.sort() sorts an array. Without a comparator, sort orders them as strings (10 before 2). For numbers, always use the comparator (a, b) => a - b.

.find() returns the first element that passes the condition. Different from .filter(), which returns all the matching elements in an array.

.slice(start, end) takes a piece of the array without changing the original. A negative index counts from the end. .reverse() flips the array's order.

What the levels ask

  1. Transform each number in the array into double its value.
  2. Take only the even numbers from the array.
  3. Take the numbers greater than 3, then multiply each by 10.
  4. Add up the total of all the prices in the array.
  5. Sort the array of numbers from smallest to largest.
  6. Find the first number greater than 50.
  7. Change each number into a string in the format "Rp{number}" then join with a comma.
  8. Sum only the numbers greater than 20000.
  9. Take the last 3 elements of the array, then reverse their order.
  10. Each string contains words separated by spaces. Split all the strings into an array of single words.
  11. Check whether every exam score is above 70. The result is a boolean.
  12. Take the 3 highest scores, sorted from largest.

And more, 15 levels in all.