๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

JavaScript2

์•Œ๊ณ ๋ฆฌ์ฆ˜ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ํ’€์ด ๋ชจ์Œ ๋‘ ์ •์ˆ˜ ์‚ฌ์ด์— ์†ํ•œ ์ •์ˆ˜์˜ ํ•ฉ ๊ตฌํ•˜๊ธฐ function solution(a, b) { return (a + b) * (Math.abs(b - a) + 1) / 2; } ๋‘ ๋ฒกํ„ฐ์˜ ๊ฐ ์„ฑ๋ถ„๋ผ๋ฆฌ์˜ ๊ณฑ์˜ ํ•ฉ์‚ฐ(๋‚ด์ ) ๊ตฌํ•˜๊ธฐ function solution(a, b) { // a, b ๋ฐฐ์—ด์˜ ๊ธธ์ด๊ฐ€ ๋™์ผํ•จ์œผ๋กœ ๊ฐ€์ • return a.reduce((acc, _, i) => acc += a[i] * b[i], 0); } 0๋ถ€ํ„ฐ 9๊นŒ์ง€์˜ ์ˆซ์ž ์ค‘ ์—†๋Š” ์ˆซ์ž ๋”ํ•˜๊ธฐ function solution(numbers) { return 45 - numbers.reduce((cur, acc) => cur + acc, 0); } 2022. 7. 8.
javascript ๊ฐ์ฒด ํ‚ค ์ด๋ฆ„ ๋ณ€๊ฒฝ ๊ฐ์ฒด ํ‚ค ์ด๋ฆ„ ๋ณ€๊ฒฝํ•˜๊ธฐ (๊ฐ์ฒด ๋ฐฐ์—ด) map ์ธ์ž๋กœ ๊ฐ์ฒด๋ฅผ ๊ตฌ์กฐ๋ถ„ํ•ดํ•˜์—ฌ ๋‹ค๋ฅธ ์ด๋ฆ„์œผ๋กœ ๋ณ€๊ฒฝํ•˜๊ณ  ์ƒˆ๋กœ์šด ๊ฐ์ฒด๋กœ ๋ฆฌํ„ดํ•œ๋‹ค. let origins = [{ old1: 'origins[0].old1', old2: 'origins[0].old2', old3: 'origins[0].old3' }, { old1: 'origins[1].old1', old2: 'origins[1].old2', old3: 'origins[1].old3' }]; let results = origins.map(({ old1: new1, old2: new2, ...rest }) => ({ new1, new2, ...rest })); ๊ฐ์ฒด ํ‚ค ์ด๋ฆ„ ๋ณ€๊ฒฝํ•˜๊ธฐ (๊ฐ์ฒด) let origin = { old1: 'origins[0].old1', old2.. 2022. 7. 8.