JavaScript every() some() and functions returning functions [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Answer:1

I've added annotations that briefly describe each functions purpose. I wouldn't solve the problem this way but none the less it explains what each part is doing

function checkUsersValid(goodUsers) {

  // allUsersValid is a function that compares lists of users against each other
  // if they do not match exactly return false if they do match return true 

  return function allUsersValid(submittedUsers) {

    // .every checks to see if every element in array passes a test
    // defined by the following function if every element passes
    // it will return true, and if not return false
    return submittedUsers.every(function(submittedUser) {

    // .some is a function that tests to see if any elements pass the
    // test defined by the function I.E. does this submitted user.id
    // match any of the goodUsers ids if so pass true else false
    // if all return true then .every returns true if any of them
    // return false then .every will return false
      return goodUsers.some(function(goodUser) {
        return goodUser.id === submittedUser.id;
      });
    });
  };
}

module.exports = checkUsersValid;
Answer:2

checkUsersValid: function returns a function with goodUsers in the scope.

allUsersValid: returns true if all submittedUsers are contained in goodUsers. goodUsers variable is available to the function via the original closure created by running checkUsersValid.

submittedUsers.every : runs callback on each element. Will return true if every callback invocation will return true.

goodUsers.some : runs callback on each element. Will return true if at least one invocation will return true.

return goodUser.id === submittedUser.id : goodUser is in the scope of the last callback. submittedUser in the parent scope.

In other words the returned function checks that all submitted users are contained in the good users. for that every submitted user needs to be referred at least once (some) in the good users.

Answer:3

I have a web server which uses SSL client authentication. A web page on that server makes a same-origin GET request using the fetch() API. In Chrome, the client cert is sent in the SSL handshake, as ...

I have a web server which uses SSL client authentication. A web page on that server makes a same-origin GET request using the fetch() API. In Chrome, the client cert is sent in the SSL handshake, as ...

I want to recreate the video animation in the background of the [Uber Developer webpage](link) programatically using JavaScript/CSS. I am defining a grid of paths (my own design, not the one on the ...

I want to recreate the video animation in the background of the [Uber Developer webpage](link) programatically using JavaScript/CSS. I am defining a grid of paths (my own design, not the one on the ...

I can't seem to get jquery to toggle multiple checkboxes. I want to grab all the checkboxes on the page with a certain name and toggle them. Here is what I am currently trying but it just generates ...

I can't seem to get jquery to toggle multiple checkboxes. I want to grab all the checkboxes on the page with a certain name and toggle them. Here is what I am currently trying but it just generates ...

  1. toggle multiple checkboxes jquery
  2. toggle multiple checkboxes
  3. javascript toggle multiple checkboxes

I try to implement an inpage shopping cart. When you click a picture of a product, the webpage shows detailed information of that product. Here's what Google Image Search does: Google Image Search ...

I try to implement an inpage shopping cart. When you click a picture of a product, the webpage shows detailed information of that product. Here's what Google Image Search does: Google Image Search ...