Learn Functional Programming by Building a Spreadsheet - Step 102

Tell us what’s happening:

Step 102

The last function has a few approaches to implement, and you are free to choose whichever approach you would like.

you are free to choose whichever approach you would like, - they say, but why not this one? Is something wrong with it?

Your code so far

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),
  nodupes: nums => nums.filter((el, i, arr) => arr.indexOf(el, i+1)<0)
}

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/121.0.0.0 Safari/537.36 Edg/121.0.0.0

Challenge Information:

Learn Functional Programming by Building a Spreadsheet - Step 102

2 Likes

what do you want this to do?

because it looks like you are deleting the first instance of a number instead of keeping it and removing the following ones
image

So how is it contro to the task of deleting all duplicates? It deletes all duplicates is it not? :slightly_smiling_face:

For example, [2, 1, 2, 5, 3, 2, 7] should return [2, 1, 5, 3, 7] .

But does it return the requested array?

1 Like

reinforced concrete argument :handshake:

can you please explain why I can’t get ‘this’ in my callback when trying this crazy idea:

const dupsOut = nums => nums.filter((el) => !this.includes(el), nums.filter((el, i, arr) => arr.indexOf(el, i+1)<0))

this with arrow functions behave not as expected, but you can also bind this to whatever you want using the second argument of filter

what do you want this to be? I don’t understand what you are trying to do

I think I grinded something like this in the “windmills of my mind” so to speak:

function dupiDupiDups(nums) {
  const dupsOut = nums => nums.filter((el,index, array) => !array.filter((el, i, arr) => arr.indexOf(el, i+1)>0).includes(el))
  return dupsOut(nums);
}

console.log(dupiDupiDups([1,3,3,34,,8,5,2,3,8]));

but it returns an array without every element that has repetition in the original array and I lost track of this idea

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