Learn Functional Programming by Building a Spreadsheet - Step 104

Tell us what’s happening:

So here’s my function:

nodupes: nums => {
    let length = nums.length;
    for (let i=0 ; i<length ; i++) {
          for (let j = 1 ; j<length ; j++) {
            if (nums[i]===nums[j]) {
              nums.splice(nums.indexOf(nums[j]), 1);
              length -= 1;
            }
          }
    }
    return nums;
  }

I don’t know what I’m missing.

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),
  nodupes: nums => {
    let length = nums.length;
    for (let i=0 ; i<length ; i++) {
          for (let j = 1 ; j<length ; j++) {
            if (nums[i]===nums[j]) {
              nums.splice(nums.indexOf(nums[j]), 1);
              length -= 1;
            }
          }
    }
    return nums;
  },
}


// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:141.0) Gecko/20100101 Firefox/141.0

Challenge Information:

Learn Functional Programming by Building a Spreadsheet - Step 104

You have to be cautious when using the splice method, as it modifies the original array (as opposed to the slice method e.g.). This can cause all manner of unwanted side-effects.

There are much simpler ways of removing duplicates from an array though… a web search should yield useful results.

Well yeah I guess I just have to copy what’s on the internet. I was just trying to pass it using what I can remember. It’s prolly not enough. Thanks again.

you can solve this with what you know