Skip to content

Instantly share code, notes, and snippets.

@munkacsitomi
Last active January 24, 2020 14:50
Show Gist options
  • Save munkacsitomi/0539e8141f487449c65ae90ccc95d2b7 to your computer and use it in GitHub Desktop.
Save munkacsitomi/0539e8141f487449c65ae90ccc95d2b7 to your computer and use it in GitHub Desktop.
Real life ES6 examples
const lastPickupDate = items => items
.filter(i => i.returnQuantity)
.map(i => i.pickupDate)
.sort((a, b) => +new Date(b) - +new Date(a))
.find(i => i);
const orderTotal = order => {
const totalNormalItems = order.items
.filter(x => !x.shipping)
.reduce((prev, cur) => prev + cur.quantity * cur.price, 0)
const shippingItem = order.items.find(x => !!x.shipping)
const shipping = totalNormalItems > 1000 ? 0 : shippingItem.price
return totalNormalItems + shipping
}
const removeDuplicates = arr => [... new Set(arr)];
const sleep = ms => (new Promise(resolve => setTimeout(resolve, ms)));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment