JS 2

[JS] Rest Syntax

1. Rest Syntax๋ž€?Rest Syntax๋Š” ํ•จ์ˆ˜๊ฐ€ ํ˜ธ์ถœ๋  ๋•Œ ์ „๋‹ฌ๋œ ๋ชจ๋“  ์ธ์ž๋ฅผ ํ•˜๋‚˜์˜ ๋ฐฐ์—ด๋กœ ๋ฐ›์•„๋“ค์ด๋Š” ๋ฌธ๋ฒ•์ž…๋‹ˆ๋‹ค. ์ฆ‰, ํ•จ์ˆ˜์˜ ๋งค๊ฐœ๋ณ€์ˆ˜ ์•ž์— ...์„ ๋ถ™์ด๋ฉด, ํ•ด๋‹น ๋งค๊ฐœ๋ณ€์ˆ˜๋Š” ๋‚˜๋จธ์ง€ ๋ชจ๋“  ์ธ์ž๋“ค์„ ๋ฐฐ์—ด๋กœ ๋ฐ›์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.์˜ˆ์ œ:function f(...args) { const sum = args[0] + args[1]; return sum;}console.log(f(3, 4)); // 7f(3, 4)๋ฅผ ํ˜ธ์ถœํ•˜๋ฉด, ํ•จ์ˆ˜ ๋‚ด๋ถ€์—์„œ args๋Š” [3, 4]๊ฐ€ ๋ฉ๋‹ˆ๋‹ค.์ด์ฒ˜๋Ÿผ ํ•จ์ˆ˜์— ์ „๋‹ฌ๋œ ๋ชจ๋“  ์ธ์ž๋ฅผ ๋ฐฐ์—ด๋กœ ๋‹ค๋ฃฐ ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ค๋‹ˆ๋‹ค.2. ์™œ Rest Syntax๋ฅผ ์‚ฌ์šฉํ• ๊นŒ?์ฒ˜์Œ์—๋Š” "๊ทธ๋ƒฅ ๋ฐฐ์—ด์„ ํ•จ์ˆ˜์— ์ „๋‹ฌํ•˜๋ฉด ๋˜๋Š” ๊ฑฐ ์•„๋‹Œ๊ฐ€?"๋ผ๋Š” ์ƒ๊ฐ์ด ๋“ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ Rest Syntax๋Š” ๊ฐ€๋ณ€์ ์ธ..

[LeetCode] 2667 create-hello-world-function

โœ” ๋ฌธ์ œ ๋งํฌhttps://leetcode.com/problems/create-hello-world-function/editorial/โœ” editorial ํ•™์Šต1. ์ต๋ช…ํ•จ์ˆ˜var f = function(a, b) { const sum = a + b; return sum;}console.log(f(3, 4)); // 7- ๋ฌด๊ธฐ๋ช… ํ•จ์ˆ˜ 2. ์ฆ‰์‹œ ์‹คํ–‰ ํ•จ์ˆ˜var res = (function () { var a = 3; var b = 5; return a + b;}())console.log(res); // 15res = (function (a, b) { return a * b;}(3, 5))console.log(res); // 15- ์ผ๋ฐ˜ ํ•จ์ˆ˜์ฒ˜๋Ÿผ ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, ์ธ์ˆ˜..