Advertisement
Guest User

Untitled

a guest
Jun 20th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. if(coupons.length) {
  2.     let wrWithDiscount = coupons.map(c => {
  3.  
  4.         let discount
  5.  
  6.         if(c.discount_percentage) {
  7.             discount = (wr.price - (wr.price * c.discount_percentage / 100))
  8.         }
  9.  
  10.         if(c.discount_price) {
  11.             discount = (wr.price - c.discount_price)
  12.         }
  13.  
  14.         return {
  15.             coupon_id: c.id,
  16.             discount: discount
  17.         }
  18.     })
  19.  
  20.     let smallest = wrWithDiscount.reduce((a, b) => (a.discount > b.discount) ? a : b)
  21.     wr.price = smallest.discount.toFixed(2)
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement