mardi 4 août 2015

Difference between JavaScript Array every and some

I see both return true or false upon given tests.

http://ift.tt/16HuOcN

http://ift.tt/YHNWr1

What should be the right case to use them both together ?

Test code:

function checkUsersValid(goodUsers) {
  return function allUsersValid(submittedUsers) {
    //Im testing arrays here
    return submittedUsers.every(function isBigEnough(element, index, array) {
          return goodUsers.some(function (el, i, arr) {
                return element.id == el.id;
          });
        });
  };
}

var goodUsers = [
      { id: 1 },
      { id: 2 },
      { id: 3 }
    ];
    
var testAllValid = checkUsersValid(goodUsers);

testAllValid([
      { id: 2 },
      { id: 1 }
    ]);

Aucun commentaire:

Enregistrer un commentaire