Skip to content

Instantly share code, notes, and snippets.

@stoneboyindc
Created February 1, 2021 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stoneboyindc/8eff782439dfe09990b321793dc2542b to your computer and use it in GitHub Desktop.
Save stoneboyindc/8eff782439dfe09990b321793dc2542b to your computer and use it in GitHub Desktop.
function allCandyOrders(inventory) {
let result = {};
for (let i=0; i<inventory.length; i++) {
if (inventory[i].inStock < inventory[i].weeklyAverage) {
result[inventory[i].candy]= inventory[i].weeklyAverage * 2;
} else {
result[inventory[i].candy] = 0;
}
}
return result;
}
@stoneboyindc
Copy link
Author

stoneboyindc commented Aug 30, 2021

function allCandyOrders  (inventory){
  let result = {};  // Creating an empty object
  for (let i=0; i<inventory.length; i++) { // loop through each candy in the inventory
    result[inventory[i].candy]= candyOrderQuantity(inventory, inventory[i].candy)  // Adding an attribute and value pair into an object
  }
  return result;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment