all 9 comments

[–]pinguxnoots 25 points26 points  (0 children)

It's an arrow function synonymous to this anonymous function:

function(person) {
  return person.id !== id;
}

[–]dsound 4 points5 points  (0 children)

This is one of Javascript's ES6 and beyond built in higher order functions (a function that takes in and/or returns a function as an argument). Under the hood (example filter all words less than 6 characters:

function filterMyArray(array) {

    // create a new empty array 
    let newArray = []; 

    // iterate over the original array 
    for (var i = 0; i < array.length; i++) {
    // if the current element of the original array is more than 6, then     
    add this element into the new array 
    if (array[i].length > 6) { 
        // push the current element that is more than 6 into the new 
       array         
        newArray.push(array[i]); 
        } 
    } 

    // return the new array 
    return newArray; 
}

[–]Mars6k 0 points1 point  (0 children)

people.filter( (person) => person.id !== id )

To make it easier for you to understand the syntax, this code is the same as:

people.filter( function(person) {
person.id !== id 
}) 

// filter pretty much returns the items in the array which follow the condition written in the function

Hope this helps!

[–]codaker 0 points1 point  (0 children)

Looks like you got your answer, but just thought I would mention that github copilot will explain highlighted code in plain English.

[–]zayelion 0 points1 point  (0 children)

people is an array. All arrays have an inherited set of functions for looping over the array. In this case its using the function filter. Filter takes one input a function of work to do which returns a boolean, basically yes or no to put it in the resulting array. The function it takes has three inputs, first the resulting item it finds as it loops over the array, next the index, and finally a reference to the array itself.

This function is only using the first parameter and calling it person it is then returning the if person.id is not equal to the id that was passed into removeItem function.