Home>

I learned that you can write an arrow function when you connect multiple arrows.
I wrote the following test code using the reduce method.

const array1 = [1, 2, 3, 4];
const test = val = (accu, cur) =>accu + cur;
console.log (test (array1))

I wanted to get "10" as the output result,
Currently, the output results are as follows.

1,2,3,4 undefined

In the case of the reduce method, isn't it possible to write by connecting arrow functions?
I would appreciate it if anyone could teach me.

  • Answer # 1

    I learned that you can write an arrow function when you connect multiple arrows.
    I wrote the following test code using the reduce method.
    ...
    In the case of the reduce method, isn't it possible to write by connecting arrow functions?

    In the code presentedreduce reduceAre you not using?
    Also, what does "writing by connecting arrow functions" mean?

    Correctly if you do the followingTenI think it will be output as ...

    const array1 = [1, 2, 3, 4];
    const test = val = (accu, cur) =>accu + cur;
    console.log (array1.reduce (test))