nodeschool / discussions

:school::speech_balloon: need help with nodeschool? or just wanna ask a question? open an issue on this repo!
489 stars 107 forks source link

functional javascript every some #2630

Closed qlake98 closed 1 year ago

qlake98 commented 2 years ago

My Code

function checkUsersValid(goodUsers) {
  return function allUsersValid(submittedUsers) {
    return submittedUsers.every(function(submittedUser) {
      return goodUsers.some(function(goodUser) {
        return goodUser.id === submittedUser.id;
      });
    });
  };
}

module.exports = checkUsersValid;

This is not my code, I copy and pasted it from stack overflow. I am trying to understand what I am looking at here. I know that from the task i am to "Return a function that takes a list of valid users". Ok, so the function that comes with the boiler plate, will now return another function and this third function will return a function if all users exist. I am confused on why we would use the every and some methods. Both check if the values are uniform, right ? Maybe things would clear up if i knew how the code was executed. Thank you in advance for reading my post and to your response.