Rest parameter practice

Tell us what’s happening:
Describe your issue in detail here.
can someone descript this code line . where a and b come from …where does the value take from

  **Your code so far**

const sum = (x, y, z) => {
const args = [x, y, z];
 this line only ==>  return args.reduce((a, b) => a + b, 0); <==
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36 Edg/92.0.902.73

Challenge: Use the Rest Parameter with Function Parameters

Link to the challenge:

this is an arrow function, there is nothing unusual with it

reduce is an higher level function, as it accepts a function as argument
in this case the reduce method will give back the sum of the elements of the array on which it is used on

You can read about reduce here, if you want to learn more:

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.