Salesforce JavaScript Developer Practice Exam

Question: 1 / 400

What is the output of the following code? [[0, 1], [2, 3]].reduce( (acc, cur) => { return acc.concat(cur); }, [1, 2]);

[0, 1, 2, 3, 1, 2]

[6, 1, 2]

[1, 2, 0, 1, 2, 3]

The provided code snippet uses the `reduce` method to flatten an array of arrays (`[[0, 1], [2, 3]]`) while also incorporating an initial accumulator value, which is `[1, 2]`.

In detail, the `reduce` function iterates through each element of the outer array. During each iteration, it takes the current value (`cur`) and concatenates it to the accumulator (`acc`).

1. Initially, the accumulator starts as `[1, 2]`.

2. In the first iteration, `cur` is `[0, 1]`. The accumulator becomes `[1, 2].concat([0, 1])`, resulting in `[1, 2, 0, 1]`.

3. In the second iteration, `cur` is `[2, 3]`. The accumulator now is `[1, 2, 0, 1].concat([2, 3])`, yielding `[1, 2, 0, 1, 2, 3]`.

This results in the final output being `[1, 2, 0, 1, 2, 3]`, which aligns with the answer provided.

Get further explanation with Examzify DeepDiveBeta

[1, 2, 6]

Next Question

Report this question

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy