Learn Functional Programming by Building a Spreadsheet - Step 103

Tell us what’s happening:

Man, I got this after some trials but i still dont get why we use the spread operator and why not provide the first and second item of the array in the first place. Would you guys mind weighing in.

Your code so far

<!-- file: index.html -->

/* file: styles.css */

/* file: script.js */
// User Editable Region

const spreadsheetFunctions = {
  sum,
  average,
  median,
  even: nums => nums.filter(isEven),
  someeven: nums => nums.some(isEven),
  everyeven: nums => nums.every(isEven),
  firsttwo: nums => nums.slice(0, 2),
  lasttwo: nums => nums.slice(-2),
  has2: nums => nums.includes(2),
  increment: nums => nums.map(num => num + 1),
  random: ([x, y]) => Math.floor(Math.random() * y + x),
  range: nums => range(...nums)
}

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36

Challenge Information:

Learn Functional Programming by Building a Spreadsheet - Step 103

Can you explain what you mean by the first and second items or where are they? If there were only two I see you point but in some instances there maybe hundreds.

i kind of get your point…and is that where the spread operator comes in

Yes, I guess the term num is an array here, the spread operator is only taking one array but it could take more like [...num, ...num2, ...num3]. Just imagine if the array had 100
numbers and all you need to type is arr1 then more arrays.

Here is an artical that I found: 10 ways to use the spread operator in JavaScript - DEV Community

The step says, " Add a range property which generates a range from the first number in nums to the second number in nums"

So I’m confused about why the official answer uses a spread operator, too. I’ll try asking this in another post.