Advertisement
Guest User

Untitled

a guest
May 29th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1.  
  2.  
  3. const product = [
  4. {id:1,product:'book',price:'100',stock:2},
  5. {id:2,product:'shoes',price:'40',stock:0},
  6. {id:3,product:'laptop',price:'30',stock:1},
  7. {id:4,product:'tablet',price:'20',stock:4},
  8. {id:5,product:'smartphone',price:'50',stock:2}
  9. ]
  10.  
  11.  
  12. //sum of stok
  13. const Total = (products) => {
  14. return product.reduce((prevVal, elem) => prevVal + elem.stock, 0);
  15.  
  16. }
  17.  
  18.  
  19. const checkStock = (products,available='true') => {
  20. return product.filter((data)=>{
  21. return data.stock !=0
  22. })
  23. }
  24.  
  25. console.log(Total(product))
  26. console.log(checkStock(product))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement