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

์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ3

์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ์œ ์šฉํ•œ ํ•จ์ˆ˜ ๋ชจ์Œ ๊ฐ์ฒด ํ‚ค ์ด๋ฆ„ ๋ณ€๊ฒฝํ•˜๊ธฐ โœ๏ธ ๊ฐ์ฒด 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.
javascript ๋ฐฐ์—ด ๋‚ด ์ค‘๋ณต ๊ฐ’ ๊ตฌํ•˜๊ธฐ ๋ฐฐ์—ด ๋‚ด์—์„œ ์ค‘๋ณต ๊ฐ’์„ ์ถ”์ถœํ•˜๋Š” ๋ฐฉ๋ฒ•์ด๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด [1, 1, 2, 3, 5] ๋ฐฐ์—ด์—์„œ ์ค‘๋ณต ๊ฐ’์ธ [1] ์„ ๊ตฌํ•˜๋Š” ๋ฐฉ๋ฒ•์ด๋‹ค. ์ค‘๋ณต ๊ฐ’์„ ๊ตฌํ•ด์•ผ ํ•˜๋Š” ๋Œ€์ƒ ๋ฐฐ์—ด์ด ๊ฐ์ฒด๋ฅผ ์š”์†Œ๋กœ ๊ฐ–๋Š” ๋ฐฐ์—ด์ด๋ผ๋ฉด ๊ฐ์ฒด์—์„œ ์ค‘๋ณต์„ ๊ฒ€์‚ฌํ•  ๋Œ€์ƒ๋งŒ ์ถ”์ถœํ•œ๋‹ค. (์ค‘๋ณต์ด ๊ฐ์ฒด ๋‚ด ๊ฐ’์ด ์•„๋‹ˆ๋ผ ๊ฐ์ฒด ์ž์ฒด๋ผ๋ฉด JSON.stringify() ๋“ฑ์œผ๋กœ ๋ณ€ํ™˜ํ•˜์—ฌ ํ™•์ธํ•ด์•ผ ํ•œ๋‹ค.) // ๋ฐ์ดํ„ฐ let arr = [{ "name": "ํ™๊ธธ๋™", "phoneNumber": "010-1111-1111" }, { "name": "๊น€๊ธธ๋™", "phoneNumber": "010-2222-2222" }, { "name": "๊ณ ๊ธธ๋™", "phoneNumber": "010-3333-3333" }, { "name": "์„œ๊ธธ๋™", "phoneNumber": ".. 2022. 6. 23.