cf.completefrontend

Predict the outputMedium

What do these flat and flatMap calls return?

What does this log?
const nested = [1, [2, [3, [4]]]];
console.log(nested.flat());
console.log(nested.flat(2));
console.log(nested.flat(Infinity));
 
console.log(["a b", "c"].flatMap((s) => s.split(" ")));
console.log([1, 2, 3].flatMap((n) => (n % 2 ? [n, n] : [])));
console.log([1, 2].flatMap((n) => [[n]]));

The answer

Work out every line it logs, in order. Then check.

Checking your sign-in…