Last active
January 24, 2020 14:50
-
-
Save munkacsitomi/0539e8141f487449c65ae90ccc95d2b7 to your computer and use it in GitHub Desktop.
Real life ES6 examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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