Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 141247

Difference between JavaScript Array every and some

$
0
0

I see both return true or false upon given tests.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every

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 }
    ]);

Viewing all articles
Browse latest Browse all 141247

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>