node-quiz icon indicating copy to clipboard operation
node-quiz copied to clipboard

Fail in the first question

Open yitsushi opened this issue 11 years ago • 3 comments

Currently,

var result = [[0, 1], [2, 3], [4, 5]].reduce(function(a, b) {
  return a.concat(b.reverse());
});
console.log(result);

And the right answer for that is:

[ 0, 1, 3, 2, 5, 4 ]

Because you did not defined the initial value.

The right answer as the question asked would be: [ 1, 0, 3, 2, 5, 4 ]

To reach this you need to initialize the "memo" as an empty array:

var result = [[0, 1], [2, 3], [4, 5]].reduce(function(a, b) {
  return a.concat(b.reverse());
}, []);
console.log(result);

Fix the question or the answer please :)

yitsushi avatar Sep 09 '14 12:09 yitsushi

Could you send a PR please?

gergelyke avatar Sep 09 '14 12:09 gergelyke

Yes if you tell me what do you want. Fix the answer of fix the question.

yitsushi avatar Sep 09 '14 12:09 yitsushi

Your call

gergelyke avatar Sep 09 '14 12:09 gergelyke