avatar

Javascript 37

  • Published on
    ## Passing Cars ### ๋ฌธ์ œ N์˜ ๊ธธ์ด๋กœ ์ด๋ฃจ์–ด์ง„ ๋ฐฐ์—ด A๋Š” 0๊ณผ 1๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ๋Š”๋ฐ, 0๊ณผ 1์€ ๊ฐ๊ฐ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์˜๋ฏธ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค. - 0์€ ์ฐจ๊ฐ€ ๋™์ชฝ์œผ๋กœ ๊ฐ„๋‹ค - 1์€ ์ฐจ๊ฐ€ ์„œ์ชฝ์œผ๋กœ ๊ฐ„๋‹ค ์ด ๋•Œ ๋™์ชฝ์œผ๋กœ ๊ฐ„ ์ฐจ์™€ ์„œ์ชฝ์œผ๋กœ ๊ฐ„ ์ฐจ๋ฅผ ์ง์ง€์„ ์ˆ˜ ์žˆ๋Š” ๊ฐœ์ˆ˜๋ฅผ ๊ตฌํ•˜๋ผ. ๋‹จ ๋จผ์ € ๋™์ชฝ์œผ๋กœ ๊ฐ„์ฐจ์™€ ๊ทธ ์ดํ›„์— ์„œ์ชฝ์œผ๋กœ ๊ฐ„ ์ฐจ๋งŒ ์ง ์ง€์„ ์ˆ˜ ...
  • Published on
    ## ์—ฐ๊ฒฐ๋ฆฌ์ŠคํŠธ ์—ฐ๊ฒฐ๋ฆฌ์ŠคํŠธ, Linked List ๋Š” ๊ฐ ๋…ธ๋“œ๋“ค์ด ํ•œ ์ค„๋กœ ์—ฐ๊ฒฐ๋˜์–ด ์žˆ๋Š” ๋ฐฉ์‹์œผ๋กœ ๊ฐ ๋…ธ๋“œ๋Š” ๋ฐ์ดํ„ฐ์™€ ํฌ์ธํ„ฐ (๋‹ค์Œ ๋…ธ๋“œ์˜ ์ •๋ณด)๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค. ์—ฐ๊ฒฐ๋ฆฌ์ŠคํŠธ๋Š” ์ผ๋ฐ˜์ ์ธ ๋ฐฐ์—ด๊ณผ ๋‹ค๋ฅด๊ฒŒ ์‚ฝ์ž…๊ณผ ์‚ญ์ œ๊ฐ€ `O(1)`์— ๊ฐ€๋Šฅํ•˜๋‹ค๋Š” ์žฅ์ ์ด ์žˆ๋‹ค. ํ•˜์ง€๋งŒ ํŠน์ • n๋ฒˆ ์งธ ์ •๋ณด๋ฅผ ์ฐพ๋Š” ๋ฐ์—๋Š” `O(n)`์‹œ๊ฐ„์ด ๊ฑธ๋ฆฐ๋‹ค๋Š” ๋‹จ์ ๋„ ์žˆ๋‹ค. ![๋‹จ์ผ ์—ฐ๊ฒฐ ๋ฆฌ์ŠคํŠธ...
  • Published on
    ### Nodejs์—์„œ์˜ ์•”ํ˜ธํ™”์™€ ๋ณตํ˜ธํ™” ๋งŒ์•ฝ ๊ฐ™์€ ํ…์ŠคํŠธ๋กœ ์•”ํ˜ธํ™”๋ฅผ ๋™์ผํ•˜๊ฒŒ ์‹œ๋„ํ–ˆ์„ ๋•Œ, ์•”ํ˜ธํ™”๋œ ๊ฒฐ๊ณผ๊ฐ€ ๋™์ผํ•˜๊ฒŒ ๋‚˜์˜จ๋‹ค๋ฉด ์ด ์•”ํ˜ธํ™”๋Š” ๊ต‰์žฅํžˆ ์•ฝํ•œ ์•”ํ˜ธํ™”๋ผ ๋ณผ ์ˆ˜ ์žˆ๋‹ค. ๊ฐ•๋ ฅํ•œ ์•”ํ˜ธํ™”๋Š” ๋งค๋ฒˆ ์•”ํ˜ธํ™”๋ฅผ ์‹œ๋„ํ•  ๋•Œ๋งˆ๋‹ค (์„ค๋ น ๊ฐ™์€ ํ…์ŠคํŠธ๋ผ ํ• ์ง€๋ผ๋„) ๋‹ค๋ฅธ ๊ฒฐ๊ณผ๊ฐ€ ๋‚˜์™€์•ผ ํ•œ๋‹ค. ๋ฌผ๋ก , ์–ด์จŒ๋“  ์•”ํ˜ธํ™” ๋˜์–ด ์žˆ๋‹ค๋Š” ์‚ฌ์‹ค ๋งŒ์œผ๋กœ๋„ ๋งŒ์กฑํ•  ์ˆ˜๋„ ์žˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ...
  • Published on
    ## ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ์Šคํ‚ฌ์„ ํ–ฅ์ƒ ์‹œํ‚ฌ 10๊ฐœ์˜ ์งˆ๋ฌธ [10 JavaScript Quiz Questions and Answers to Sharpen Your Skills](https://typeofnan.dev/10-javascript-quiz-questions-and-answers/) ์˜ ์งˆ๋ฌธ์„ ๋ณด๊ณ , ๋‹ต์— ๋Œ€ํ•œ ํ•ด์„์„ ์ œ๋ฉ‹๋Œ€๋กœ ์จ๋ณด์•˜์Šต๋‹ˆ๋‹ค. ### 1....
  • Published on
    ## Generator ์ œ๋„ค๋ ˆ์ดํ„ฐ์˜ ๊ฐœ๋…์— ๋Œ€ํ•ด ์ดํ•ดํ•˜๊ธฐ ์ „์—, ๋จผ์ € ๋ฐ˜๋ณต์ž (Iterator)์— ๋Œ€ํ•ด ์•Œ์•„๋ณด์ž. ### 0. Iterator ๋ฐ˜๋ณต์ž๋Š”, ๋‘๊ฐœ์˜ ์†์„ฑ (`value`์™€ `done`)์„ ๋ฐ˜ํ™˜ํ•˜๋Š” `next()`๋ฉ”์†Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ [Iterator protocal](https://developer.mozilla.org/en-US/docs/W...