Success and Failure Callback Functions: i dont get the every method

I was working on the exercise(, the thing is that i dont get what does item do on order.every method, library.js.


const inventory = {
  sunglasses: 1900,
  pants: 1088,
  bags: 1344

const checkInventory = (order) => {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      let inStock = order.every(item => inventory[item[0]] >= item[1]);
      if (inStock) {
        resolve(`Thank you. Your order was successful.`);
      } else {
        reject(`We're sorry. Your order could not be completed because some items are sold out.`);
    }, 1000);

module.exports = { checkInventory };


const {checkInventory} = require('./library.js');

const order = [['sunglasses', 1], ['bags', 2]];

// Write your code below:
const handleSuccess = (resolveValue) =>{

const handleFailure = (rejectionReason) =>{

  .then(handleSuccess, handleFailure);

help me, pls

The .every() method checks whether every item in an array passes some test provided in the proceeding callback function. In the case of library.js, it checks whether every item quantity provided in the order array is less than or equal to the total units left in the inventory object.

For example, if I provide the following order, it will return true because the order numbers are less than the inventory numbers:

let order = [['sunglasses', 100], ['pants', 200]]

However, if I provide this order, then it will return false because at least one of the order numbers is greater than the corresponding inventory numbers:

let order = [['sunglasses', 100], ['pants', 1200]]

Even though my order for sunglasses didn’t change, one of the order numbers exceeded the inventory number, so the .every() method would return false because every element in the array has to pass to return true.


Not sure what you mean.

nvm, i was comparing the results of the every().
i said that is like:

item => inventory[item[0]] >= item[1]

inventory.sunglasses >= order[0][1];

both have the same result
btw thank you for help me understand, the every method