map

๊น€๋‚จ๊ฒฝยท2022๋…„ 11์›” 17์ผ
0

catch errors

๋ชฉ๋ก ๋ณด๊ธฐ
1/16

์˜ˆ์ œ

๐Ÿ“— ๋ฐฐ์—ด์•ˆ์˜ ๊ฐ์ฒด ๊ฐ’ ๋ณ€๊ฒฝํ•˜๊ธฐ

let array = [
  {number : [1,2,3]},{number : [2,3,4]},{number : [4,5,6]}
];

function x(array){
	return array.map(x => {
      const sum = x.number.reduce((a,b) => { return a+b }, 0);
      const average = sum/x.number.length;
      //return x.number = average;
      //์ด๋ ‡๊ฒŒ ๋๋‚˜๋ฉด ๊ฒฐ๊ณผ [2,3,5];
      x.number = average;
      return x;
      //์ด๋ ‡๊ฒŒ x ๊ทธ์ž์ฒด๋ฅผ ๋Œ๋ ค์ฃผ์–ด์•ผํ•จ
      //[{number:2},{number:3},{number:5}]
    });
}

profile
๊ธฐ๋ณธ์— ์ถฉ์‹คํ•˜๋ฉฐ ์•ž์œผ๋กœ ๋ฐœ์ „ํ•˜๋Š”

0๊ฐœ์˜ ๋Œ“๊ธ€