Learn Functional Programming by Building a Spreadsheet - Step 100

Tell us what’s happening:

Hello everyone,
Do I understand thequestion?

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: (start, end) => Array(end - start + 1).fill(start).map((element, index) => element + index),
}

console.log(spreadsheetFunctions.range(1, 5)) // output [ 1, 2, 3, 4, 5 ]

Your code so far

WARNING

The challenge seed code and/or your solution exceeded the maximum length we can port over from the challenge.

You will need to take an additional step here so the code you wrote presents in an easy to read format.

Please copy/paste all the editor code showing in the challenge from where you just linked.

Replace these two sentences with your copied code.
Please leave the ``` line above and the ``` line below,
because they allow your code to properly format in the post.

Your browser information:

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

Challenge Information:

Learn Functional Programming by Building a Spreadsheet - Step 100

where is the problem.?

coder99,
Thanks for your question. Problem is code does not pass.

your range property should have a nums with arrow function then pass nums as a spread operator in range its not that long and complex that u have made it

coder99,
Thanks your reply. I thought we need two arguments not just a spread operator of nums passing to the created range function.
Kindly explain

nums arrow function then range pass nums using spread operator

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)
}

Thank you for your help.

2 Likes

hi! do you mind explaining why spreading the nums array work when the range function defined requires two parameters (start and end)?

Hi,
As much as I know, spread operaor allows us to expand elements of an iterable (like an array or string) or object properties into places where multiple elements or properties are expected .

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