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

JS2

์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ์œ ์šฉํ•œ ํ•จ์ˆ˜ ๋ชจ์Œ ๊ฐ์ฒด ํ‚ค ์ด๋ฆ„ ๋ณ€๊ฒฝํ•˜๊ธฐ โœ๏ธ ๊ฐ์ฒด const originObj = { old1: '๊ฐ’1', old2: '๊ฐ’2', old3: '๊ฐ’3', old4: '๊ฐ’4', old5: '๊ฐ’5' }; const func = ({old1: new1, old2: new2, ...rest}) => { return {new1, new2, rest}; } const newObj = func(originObj); console.log(newObj); โœ๏ธ ๊ฐ์ฒด ๋ฐฐ์—ด const originList = [{ old1: '๊ฐ’1', old2: '๊ฐ’2', old3: '๊ฐ’3', old4: '๊ฐ’4', old5: '๊ฐ’5' }, { old1: '๊ฐ’1', old2: '๊ฐ’2', old3: '๊ฐ’3', old4: '๊ฐ’4', old5: '๊ฐ’5' }]; con.. 2022. 8. 29.
์•Œ๊ณ ๋ฆฌ์ฆ˜ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ํ’€์ด ๋ชจ์Œ ๋‘ ์ •์ˆ˜ ์‚ฌ์ด์— ์†ํ•œ ์ •์ˆ˜์˜ ํ•ฉ ๊ตฌํ•˜๊ธฐ 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.