Addition assignment(+=)

Doyoon Lee·2020년 7월 26일
0

Javascript

목록 보기
19/23

Addition assignment (+=) 복합대입연산자

definition of assign : to give a particular job or piece of work to someone

definition of operand : a number or quantity that has something done to it in a calculation. For example, in 7 + y, 7 and y are the operands.

Addition assignment의 기능

operand 의 값을 더하고, 그 더한 값을 변수에 주는 기능을 한다.

My solution

function getData(salesArr, reviewArr, likeArr) {
   
    let sumAmount = 0; 
    let sumReview = 0; 
    let sumLike = 0;
    
    for (let i = 0; i < salesArr.length; ++i) {
      sumAmount += salesArr[i][1];
    }
    
    for (let j = 0; j < reviewArr.length; ++j) {
      sumReview += reviewArr[j][1];
    }
    for (let q = 0; q < likeArr.length; ++q) {
      sumLike += likeArr[q][1];
    }
  
    let objData = {
      sumAmount : sumAmount,
      sumLike : sumLike,
      sumReview : sumReview
    };
    return objData;
  }
  
  getData([["20190401", 34], ["20190402", 23], ["20190403", 29]], [["20190328", 3], ["20190401", 0], ["20190403", 1]], [["20190328", 98], ["20190401", 102], ["20190403", 125]]);
  

Better Solution

0개의 댓글