Skip to content

Instantly share code, notes, and snippets.

@Sarav-S
Last active July 20, 2020 05:49
Show Gist options
  • Save Sarav-S/876845ec8fd0377037058ec6dfede677 to your computer and use it in GitHub Desktop.
Save Sarav-S/876845ec8fd0377037058ec6dfede677 to your computer and use it in GitHub Desktop.
const cart = {
items: [
{ name: 'Item 1', value: 200, in_stock: true },
{ name: 'Item 2', value: 100, in_stock: false },
{ name: 'Item 3', value: 200, in_stock: true },
]
}
// Using traditional javascript
const inStock = items => items.filter(item => item.in_stock);
const inStockItems1 = inStock(cart.items);
const inStockItems2 = inStock(cart.items);
console.log(inStockItems1 === inStockItems2) // returns false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment