Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. class Cart extends Component {
  2. constructor(props) {
  3. super(props);
  4. this.add = this.add.bind(this);
  5. }
  6. componentDidMount() {
  7. this.props.getCart();
  8. }
  9.  
  10. add(array) {
  11. let num = [];
  12. let parse = [];
  13. console.log(array);
  14. for (let i = 0; i < array.length; i++) {
  15. parse.push(array[i].price);
  16. }
  17. console.log(parse);
  18. for (let i = 0; i < parse.length; i++) {
  19. num.push(parseInt(parse[i]));
  20. }
  21. console.log(num);
  22. let sum = num.reduce((acc, val) => {
  23. return acc + val;
  24. }, 0);
  25. console.log(sum);
  26. }
  27. render() {
  28. const { cart } = this.props.itemReducer;
  29. this.add(cart);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement