Subjects › JavaScript

Arrays and iteration

map, filter, reduce, and which methods mutate.

The idea

The mutating/non-mutating split is the thing that actually causes bugs. sort and reverse mutate; map and filter do not; splice mutates and slice does not, and their names are one letter apart.

Lesson

No lesson built yet. The worked solutions below are the material it would be assembled from.

Questions (4)

Question Type Difficulty Drift Accuracy
What does [1, 2, 3].map(x => x * 2) return, and what happens to the original array? mcq Easy -1.00 — — (0)
Which of these array methods MUTATES the array it is called on? mcq Moderate 0.20 — — (0)
What does [1, 2, 3, 4].reduce((a, b) => a + b, 10) evaluate to? numeric Hard 0.50 — — (0)
What does [10, 9, 1, 2].sort() return? mcq Hard 1.20 — — (0)