๋ฌธ์ œ

์–ด๋–ค ์ •์ˆ˜๋“ค์ด ์žˆ๋‹ค. ์ด ์ •์ˆ˜๋“ค์˜ ์ ˆ๋Œ“๊ฐ’์„ ์ฐจ๋ก€๋Œ€๋กœ ๋‹ด์€ ์ •์ˆ˜ ๋ฐฐ์—ด์—์„œ, ์‹ค์ œ ์ •์ˆ˜๋“ค์˜ ํ•ฉ์„ ๊ตฌํ•˜์—ฌ returnํ•ด๋ผ

 

์ˆ˜ํ•™๊ฐœ๋…

์ ˆ๋Œ“๊ฐ’(absolute value)

: ์–ด๋–ค ๊ฐ’์„ ์–‘์ˆ˜๋กœ ๋งŒ๋“ค์–ด์ฃผ๊ธฐ ์œ„ํ•œ ์žฅ์น˜

 

์ •์ˆ˜

: ์–‘์˜์ •์ˆ˜, 0, ์Œ์˜ ์ •์ˆ˜์˜ ์ด์นญ

 

์ฝ”๋“œ

const solution = (absolutes, signs) => {
  let answer = absolutes.map((num, idx) => signs[idx] ? num : parseInt(-num)).reduce((a, b) => a + b);
  return answer;
}

+ Recent posts