yus
@uiseok0514
Reviews Written
-
Average Rating
-
# <div align="center">์ปดํจํฐ ์ธ์์์ ์ง์ ์ง๋ ์์ ๊ฐ</div>
> #### ๐ก ์ํํธ์จ์ด์ ์ธ์์ ๋ด๊ฐ ์์ํ ๋๋ก ์ง์ ์ง์ ์ ์๋ ์ฐฝ์กฐ์ ๊ณต๊ฐ์ด๋ผ๊ณ ์๊ฐํฉ๋๋ค. ๋ ๊ณ ๋ธ๋ก๊ณผ ๊ฐ์ ๊ตฌ์ฑ์์๋ค์ ์กฐํฉํ์ฌ ํ๋ก๊ทธ๋จ์ด๋ ์ปค๋ค๋ ์ง์ ์์ฑํ๋ ๊ฒ์ ํ๋์ ์์ ๊ณผ ๊ฐ์ต๋๋ค. ์ด ์์ ์ ๋ง์ ์ฌ๋๋ค๊ณผ ๊ณต์ ๋ ๋ ์ง์ ํ ๊ฐ์น๊ฐ ๋ฐํ๋๋ค๊ณ ๋ฏฟ๊ณ , ๋ ์ข์ ํ๋ก๊ทธ๋จ์ ๋ง๋ค ์ ์๋๋ก ํฉ๋ฆฌ์ ์ธ ์ํคํ ์ณ์ ํจ๋ฌ๋ค์์ ๊ณต๋ถํด ๋๊ฐ๋ ๊ฐ๋ฐ์๊ฐ ๋๋ ค๊ณ ํฉ๋๋ค.
<br/>
## โช๏ธ Stack
| Index | Main | Sub |
|---|---|---|
| Languages | <img src="https://img.shields.io/badge/JavaScript-F7DF1E?style=for-the-badge&logo=javascript&logoColor=white"/> <img src="https://img.shields.io/badge/TypeScript-3178C6?style=for-the-badge&logo=TypeScript&logoColor=white"> | <img src="https://img.shields.io/badge/Python-3776AB?style=for-the-badge&logo=Python&logoColor=white"> <img src="https://img.shields.io/badge/Java-007396?style=for-the-badge&logo=OpenJDK&logoColor=white"/> |
| Backend | <img src="https://img.shields.io/badge/Node.js-339933?style=for-the-badge&logo=Node.js&logoColor=white"> <img src="https://img.shields.io/badge/Express-000000?style=for-the-badge&logo=Express&logoColor=white"> <img src="https://img.shields.io/badge/nestjs-E0234E?style=for-the-badge&logo=nestjs&logoColor=white"> | <img src="https://img.shields.io/badge/NGINX-009639?style=for-the-badge&logo=Nginx&logoColor=white"> <img src="https://img.shields.io/badge/PM2-2B037A?style=for-the-badge&logo=PM2&logoColor=white"> <img src="https://img.shields.io/badge/GoogleDomains-4285F4?style=for-the-badge&logo=GoogleDomains&logoColor=white"> |
| DataBase | <img src="https://img.shields.io/badge/Postgresql-4169E1?style=for-the-badge&logo=Postgresql&logoColor=white"> <img src="https://img.shields.io/badge/mongoDB-47A248?style=for-the-badge&logo=MongoDB&logoColor=white">||
| Frontend | | <img src="https://img.shields.io/badge/HTML5-E34F26?style=for-the-badge&logo=HTML5&logoColor=white"> <img src="https://img.shields.io/badge/CSS3-1572B6?style=for-the-badge&logo=CSS3&logoColor=white"> <img src="https://img.shields.io/badge/React-61DAFB?style=for-the-badge&logo=React&logoColor=white"> |
<br/>
## โช๏ธ ์ฃผ์ ํฌ์คํธ
- [ JavaScript ] ํด๋ก์ (Closure) ์ ๋ํ ๊ณ ์ฐฐ (์ฐธ์กฐ ์๋ฆฌ์ ์ํ ์ดํด) https://velog.io/@uiseok0514/JS-Closure
- [ JavaScript ] ๋น๋๊ธฐ์ฒ๋ฆฌ ๋ฌธ๋ฒ์ ๋ํ ๊ณ ์ฐฐ (Promise, async/await) https://velog.io/@uiseok0514/js-asyncronous-grammar
- [ JavaScript ] ์๋ฐ์คํฌ๋ฆฝํธ์ ๊ฐ์ฒด์ ํจ์์ ํด๋์ค https://velog.io/@uiseok0514/JS-object-function-class
- [ JavaScript ] ์ดํฐ๋ ์ดํฐ, ์ ๋๋ ์ดํฐ, ์ง์ฐํ๊ฐ https://velog.io/@uiseok0514/JS-iterator-lazyevaluation-generator
- [ TypeScipt ] @decorator ๋? https://velog.io/@uiseok0514/TS-Decorator-feat-nestJS
- [ Network ] TCP https://velog.io/@uiseok0514/Networks-TCP
- [ Network ] SSL https://velog.io/@uiseok0514/Networks-SSL
- [ Project ] BilliG ํ๋ก์ ํธ์ ๋ํ ํ๊ณ https://velog.io/@uiseok0514/Project-BilliG
<br/>
## โช๏ธ ์คํฐ๋ ์ ํ๋ธ
- ํ๋ฌํ ํฌ ์คํฐ๋ (YouTube) : https://www.youtube.com/@blackRabbitTech/search?query=%EC%9C%A0%EC%9D%98%EC%84%9D
<br/>
## โช๏ธ ์ฃผ์ ํ๋ก์ ํธ
<div align="center">
<a href="https://github.com/ObO314/ObO-back" >
<img src="https://user-images.githubusercontent.com/116103097/231535114-3f62329b-9555-4738-846d-4dde50984e17.jpg" width="400" height="300"></a>
<a href="https://github.com/BilliG-14/BilliG-BACK.git" >
<img src="https://user-images.githubusercontent.com/116103097/210710475-02c9ccf8-48af-47b2-81fa-11e9a369e648.jpeg" width="400" height="300"></a>
<a href="https://github.com/LYUHIT/ojakkyu" >
<img src="https://user-images.githubusercontent.com/116103097/202667837-11dcb9e0-185b-4c0b-88fe-8725b347fac3.jpg" width="400" height="300"></a>
<a href="https://github.com/LYUHIT/marketpass" >
<img src="https://user-images.githubusercontent.com/116103097/202356457-db68f4dd-e1dd-42c4-add2-23beebc56583.png" width="400" height="300"></a>
</div>
Posts
Q&A
a.then()์ return ํ๋ ์ด์ ๊ฐ ๋ญ๊ณ ์ด๋ป๊ฒ ๋์ํ๋ ๊ฑด๊ฐ์?
์์ ๊ฐ์์์๋ return ๊ด๋ จ ์ง๋ฌธ์ด ์์ด์ ํผ์ ๊ณ ๋ฏผํด๋ณด์๋๋ฐ ์ฌ๊ธฐ๋ ๋น์ทํ ์ง๋ฌธ์ด ์์ด ๋ต๋ณ์ ๋จ๊ฒจ๋ด ๋๋ค.๋์์ด ๋์๊ธธ ๋ฐ๋๋๋ค.---------------------------------------------go ํจ์ ์ ๋ ฅ ๊ฐ :go([Promise.resolve(1), Promise.resolve(2), Promise.resolve(3)], Lmap(a => a + 10), take(2), console.log)1. ๋ฆฌํด์ ํ์ง ์์ ๋const take = curry((l, iter) => { let res = [] iter = iter[Symbol.iterator](); return function recur() { let cur; while (!(cur = iter.next()).done) { const a = cur.value if (a instanceof Promise) a.then(a => { res.push(a); return res.length == l ? res : recur() }); res.push(a); if (res.length == l) return res; } return res; }() }) [ Promise { }, Promise { } ]go์ ๋ค์ด ์๋ Promise.resolve(1) ๊ฐ์ 1 ๋ก resolve (fulfilled) ๋ ํ๋ก๋ฏธ์ค ๊ฐ์ฒด์ ๋๋ค.์ด ๊ฐ์ฒด๊ฐ Lmap์ ํต๊ณผํ๊ฒ ๋๋ฉด,Lmap์ ๊ตฌ์ฑํ๋ go1 ํจ์์ ์ํ์ฌ a.then()ํํ์ ํ๋ก๋ฏธ์ค ๊ฐ์ฒด๋ก ๋ฐํ๋๊ฒ ๋ฉ๋๋ค.์ด ๊ฐ์ฒด๋ฅผ ๋ฐ์ take ํจ์๋ while ๋ฌธ์์ ํ๋ก๋ฏธ์ค ๊ฐ์ฒด์ธ์ง ํ๋ณ ํ ํ๋ํฉ๋๋ค. ํ๋ก๋ฏธ์ค๊ฐ ์๋ ์ผ๋ฐ ๊ฐ์ ๊ฒฝ์ฐ, ๋ฐ๋ก res ๋ฐฐ์ด์ ์ถ๊ฐ ๋ฉ๋๋ค. ๋ฐ๋ฉด์ ํ๋ก๋ฏธ์ค ๊ฐ์ฒด์ผ ๊ฒฝ์ฐ, a.then()์ผ๋ก ์๋ก์ด ํ๋ก๋ฏธ์ค๋ฅผ ์์ฑํ๊ฒ ๋ฉ๋๋ค. ์ด๊ฒ์ return ํ์ง ์์ผ๋ฉด take ํจ์๋ ๊ณ์ ์ฝ ์คํ์์ ๋์ํ๊ณ ์๊ฒ ๋๊ณ , ํ๋ก๋ฏธ์ค ๊ฐ์ฒด์ ์ฝ๋ฐฑํจ์๊ฐ ์คํ๋ ์ ์์ต๋๋ค.๋ฐ๋ผ์ while๋ฌธ ์์์๋ res์ ๋ฃ์ด์ง๋ ๊ฐ๋ค์ด take ํจ์๊ฐ ์คํ๋๊ณ ์์ ๋๋ resolve ๋์ง ๋ชปํ ๊ฐ์ฒด๋ค์ด ๋ฃ์ด์ง๊ฒ ๋ฉ๋๋ค. ๊ทธ ํ console.๋ก ์ถ๋ ฅํ์์ผ๋, res์์๋ ํ๋ก๋ฏธ์ค ๊ฐ์ฒด๊ฐ ๋ค์ด์๋ ๊ฒ์ผ๋ก ์ฐํ๋๋ค.2. ๋ฆฌํด์ ํ ๋const take = curry((l, iter) => { let res = [] iter = iter[Symbol.iterator](); return function recur() { let cur; while (!(cur = iter.next()).done) { const a = cur.value if (a instanceof Promise) return a.then(a => { res.push(a); return res.length == l ? res : recur() }); res.push(a); if (res.length == l) return res; } return res; }() })[ 11, 12 ]return์ ํด์ฃผ๊ฒ ๋๋ฉด, take ํจ์๋ a.then()์ผ๋ก ๋ฐํ๋ ํ๋ก๋ฏธ์ค ๊ฐ์ฒด๋ฅผ ๋ฐํํ๊ณ ์ข ๋ฃ๋ฉ๋๋ค. go์ ์ํด์ ํ๋ก๋ฏธ์ค ๊ฐ์ฒด๋ ๋ค์ console.log๋ก ์ ๋ฌ ๋ ํ ๋ฐ, go ํจ์๋ฅผ ๊ตฌ์ฑํ๊ณ ์๋ reduce์if (acc instanceof Promise) return acc.then(recur)์ด ๋ถ๋ถ์ ์ํด์ go ์์ฒด๊ฐ ํ๋ก๋ฏธ์ค๋ฅผ ๋ฐํํ๋ฉฐ ์ข ๋ฃ๋๊ฒ ๋ฉ๋๋ค.์ง๊ธ๊น์ง ์ข ๋ฃ๋ ํจ์๋ 2๊ฐ ์ ๋๋ค. ์ฒ์์ take๊ฐ ํ๋ก๋ฏธ์ค๋ฅผ ๋ฐํํ๋ฉฐ ์ข ๋ฃ๋๊ณ , ๊ทธ ํ๋ก๋ฏธ์ค๋ฅผ ๋ฐ์ go๊ฐ reduce์ ์ํด ํ๋ก๋ฏธ์ค๋ฅผ ๋ฐํํ๋ฉฐ ์ข ๋ฃ๋ฉ๋๋ค.์ด ๋ ๋น๋ก์ ์ฝ ์คํ์ด ๋น์์ง๊ณ , take ์์ ๋ฐํํ๋ ํ๋ก๋ฏธ์ค์ ์ฝ๋ฐฑ์ด ์คํ๋ฉ๋๋ค.a => { res.push(a); return res.length == l ? res : recur() });res์ a (์ฌ๊ธฐ์๋ Promise.resolve(1)๋ก ๋ถํฐ ๋ฐ์ '1')๋ฅผ ์ ์ฅํ๊ณ , ์กฐ๊ฑด๋ฌธ์ ์ถฉ์กฑํ์ง ๋ชปํ์ผ๋ฏ๋ก, take ์ผ์์ recur๋ฅผ ํธ์ถํฉ๋๋ค.๋ค์ ๋ฃจํ์์ while ๋ฌธ์ด ์ข ๋ฃ๋๊ณ , res๋ฅผ ๋ฐํํฉ๋๋ค.res๋ฅผ ๋ฐํํ๋ฉด ์ด๊ฒ์ reduce๊ฐ ์์ฑํ ํ๋ก๋ฏธ์ค์ resolve ๊ฐ์ด ๋๋ฏ๋ก, go ํจ์์ ์๋ console.log ๊ฐ ์คํ๋ฉ๋๋ค.console.log๋ res์ ๊ฐ์ธ [11,12] ๋ฅผ ์ถ๋ ฅํฉ๋๋ค.
- 5
- 7
- 859
Q&A
์ง๋ฌธ์์ต๋๋ค...
ํฅ๋ฏธ๋ก์ด ์ง๋ฌธ์ด์ด์ ์ ๋ ๊ณ ๋ฏผํ๊ณ ์ฝ๋๋ก ๋๋ ค๋ณด๋ค๊ฐ ์ด๋์ ๋ ์ดํดํ ๊ฒ ๊ฐ์ ์ ๋ฆฌํด์ ์ฌ๋ ค๋ด ๋๋ค.์ด ์ง๋ฌธ์ผ๋ก ๊ณ ๋ฏผํ์๋ ๋ถ๋ค๊ป ๋์์ด ๋๊ธธ ๋ฐ๋๋๋ค.-----------------------------------------------๋จผ์ ์ค์ํ ๊ฐ๋ ์ ํ๋ก๋ฏธ์ค๋ฅผ ๊ฐ์ฒด๋ก ๋ฐ๋ผ๋ณด์์ผ ํ๋ ๊ฒ ์ ๋๋ค. ๋ํ ํ๋ก๋ฏธ์ค ๊ฐ์ฒด๋ฅผ ์์ฑํ ๋, ์ฝ๋ฐฑํจ์๋ ์ฆ์ ์คํ๋์ง๋ง, then() ์ผ๋ก ์์ฑ๋๋ ํ๋ก๋ฏธ์ค ๊ฐ์ฒด์ ์ฝ๋ฐฑ์ ์ฝ์คํ์ด ๋น์์ง ์ดํ์ ์คํ๋๋ค๋ ์ ์ ๊ธฐ์ตํด์ผ ํฉ๋๋ค.์คํํ go :go(1, a => a + 10, a => Promise.resolve(a + 100), a => a + 1000, a => a + 10000, console.log ) 1. return์ ๋ถ์ด์ง ์์์ ๊ฒฝ์ฐconst reduce = curry((f, acc, iter) => { if (!iter) { iter = acc[Symbol.iterator]() acc = iter.next().value; } else { iter = iter[Symbol.iterator]() } return go1(acc, function recur(acc) { let cur while (!(cur = iter.next()).done) { const a = cur.value console.log(acc) acc = f(acc, a) if (acc instanceof Promise) acc.then(recur) // return ์ฌ๋ถ์ ๋ฐ๋ฅธ ๋ณํ } return acc; } ) }) 1 11 Promise { 111 } [object Promise]1000 [object Promise]100010000 [object Promise]100010000reduce ๋ด๋ถ์ console.log๋ฅผ ์์ฑํ์ฌ acc ๊ฐ์ด ์ด๋ป๊ฒ ๋ณํํ๋์ง ํ์ธํด ๋ณด์์ต๋๋ค.return์ ํ์ง ์๊ฒ๋๋ฉด, go1 ๋ด๋ถ์ while ๋ฌธ์ด ๋๋ฉด์ ์ด์ ์ ์ฌ์ฉํ๋ acc๋ฅผ ๊ทธ๋๋ก ๊ฐ์ ธ๊ฐ๊ฒ ๋ฉ๋๋ค.acc๋ f(acc, a) ์ด๋ฏ๋ก ์ ๋จ๊ณ์ acc ๊ฐ ํ๋ก๋ฏธ์ค ๊ฐ์ฒด์ด๊ฑฐ๋, ๋๋ a ํจ์๊ฐ ํ๋ก๋ฏธ์ค ๊ฐ์ฒด๋ฅผ ๋ฐํํ๋ ํจ์๋ผ๋ฉด, f(acc,a)๋ ํ๋ก๋ฏธ์ค ๊ฐ์ฒด๋ฅผ ๋ฐํํ๊ฒ ๋๊ณ , ์ด๋ฒ ๋จ๊ณ์ acc ๋ ํ๋ก๋ฏธ์ค ๊ฐ์ฒด๊ฐ ๋ ๊ฒ์ ๋๋ค.์ฝ๋์์ acc.then(recur) ์ ๋จ์ํ ํ๋ก๋ฏธ์ค ๊ฐ์ฒด๋ฅผ ์์ฑ๋ง ํ๋ ๊ฒ์ ๋๋ค. ์ฌ๊ธฐ์๋ recur ํจ์๊ฐ ์คํ๋์ง ์๊ณ , ์ ํ๋ ํ๋ก๋ฏธ์ค๊ฐ ์๋ฃ๋๊ณ ์ฝ์คํ์ด ๋น์์ง ์ดํ์ ์คํ๋ฉ๋๋ค. ๊ทธ๋ฌ๋ reduce ํจ์๊ฐ ์ข ๋ฃ๋์ง ์์์ผ๋ฏ๋ก, ์ฝ ์คํ์ด ๋น์์ง์ง ์์ต๋๋ค. ๋ฐ๋ผ์ acc์ acc.then() ํ๋ก๋ฏธ์ค ๊ฐ์ฒด ๋ชจ๋ resolve ๋์ง ๋ชปํ ์ฑ while๋ฌธ์ด ์งํ๋ฉ๋๋ค.๊ทธ ๋ง์ then()์ผ๋ก ์์ฑ๋ promise๊ฐ resolve ๋๋ ๊ฒ์ ๊ธฐ๋ค๋ฆฌ์ง ์๊ณ ,(์ฝ์คํ์ด ๋น์์ ธ์ผ ๋น๋ก์ ํ๋ก๋ฏธ์ค๊ฐ ์คํ๋์ด fulfilled ๋ ๊ฐ์ด ๋ฐํ๋๋ฏ๋ก) ๋ค์ while ๋จ๊ณ๋ก ํ๋ก๋ฏธ์ค ๊ฐ์ฒด๋ฅผ ๋๊ฒจ ๋ฐ๋ณต๋ฌธ์ ์ด์ด๊ฐ๋ ๊ฒ์ ๋๋ค. ์ฆ, ๋ค์ while๋ฌธ์์ acc ๊ฐ์ด ๋ฐ๋ ๊ฐ์ 'fulfilled ๋์ด 111๋ก resolve๋ ์ํ' ์ Promise ๊ฐ์ฒด ์ ๋๋ค. (then()์ผ๋ก ์์ฑ๋ ํ๋ก๋ฏธ์ค๊ฐ ์คํ๋ ๊ฒ์ด ์๋) ๋ฐ๋ผ์ go ์ ๋๋ฒ ์งธ ํจ์์ฒ๋ผ, ์ค๊ฐ์ ํ๋ก๋ฏธ์ค๋ฅผ ๋ฐํํ๋ ์ธ์๊ฐ ์์๊ฒฝ์ฐ while๋ฌธ์ ํ๋ก๋ฏธ์ค๊ฐ ํด๊ฒฐ๋๋ ๊ฒ์ ๊ธฐ๋ค๋ฆฌ์ง ์์ ์ฑ ํ๋ก๋ฏธ์ค ๊ฐ์ฒด ์์ฒด๋ฅผ ์ง์ ํ์ฉํ๊ฒ๋๊ณ , ๋ค์ํจ์์ธ a => a + 1000 ๋, ์ด ํ๋ก๋ฏธ์ค ๊ฐ์ฒด๋ฅผ string ์ฒ๋ผ ์ธ์ํ์ฌ Promise { 111 } ์ ๋ค๊ฐ '1000' ์ด๋ผ๋ string ๊ฐ์ ๋ถ์ฌ๋ฒ๋ฆฌ๊ฒ ๋ ๊ฒ์ ๋๋ค. 2. return ์ ํด์ฃผ์์ ๊ฒฝ์ฐconst reduce = curry((f, acc, iter) => { if (!iter) { iter = acc[Symbol.iterator]() acc = iter.next().value; } else { iter = iter[Symbol.iterator]() } return go1(acc, function recur(acc) { let cur while (!(cur = iter.next()).done) { const a = cur.value console.log(acc) acc = f(acc, a) if (acc instanceof Promise) return acc.then(recur) // return ์ฌ๋ถ์ ๋ฐ๋ฅธ ๋ณํ } return acc; } ) })1 11 111 1111 11111 11111 ๋ฐ๋ฉด์ return์ ํด์ฃผ์์ ๊ฒฝ์ฐ while๋ฌธ์ด ๋๊ณ ์๋ go1 ํจ์ ์์ฒด๊ฐ ์ข ๋ฃ๋๊ณ , ํ๋ก๋ฏธ์ค ๊ฐ์ฒด์ธ acc...(1) ๊ฐ resolve ๋๋ฉด recur ํจ์๋ฅผ ์คํํ๊ฒ ๋ค๋ ์๋ก์ด ํ๋ก๋ฏธ์ค ๊ฐ์ฒด...(2) ๋ฅผ ์์ฑํ์ฌ ๊ฐ์ผ๋ก ๋ฐํํฉ๋๋ค.์ด ๋ฐํ๋ ๊ฐ์ ๊ฒฐ๊ตญ reduce์ ๋ฐํ ๊ฐ์ด๋ฉฐ, reduce๊ฐ ์คํ๋๋ ์ฝ์คํ์ ์ผ์์ ์ผ๋ก ๋น์์ง๋๋ค.(1) acc ํ๋ก๋ฏธ์ค ๊ฐ์ฒด๊ฐ resolve ๋๊ณ (์ ์ด์ resolve๋ ์ํ๋ก ์์ฑ๋์์ง๋ง), ์ฝ์คํ์ด ๋น์์ก์ผ๋ฏ๋ก microQueue ์ (2) ํ๋ก๋ฏธ์ค์ ์ฝ๋ฐฑ์ด ๋ค์ด๊ฐ๊ณ ์คํ๋ฉ๋๋ค. ์ฌ๊ธฐ์ ๋ค์ recur ํจ์๊ฐ ์คํ๋ฉ๋๋ค.recur ํจ์๊ฐ ์ฐธ์กฐํ๋ ๊ฐ๋ค์ ๋ชจ๋ ํด๋ก์ ๋ก ์ ์ง๊ฐ ๋๊ณ ์๊ธฐ ๋๋ฌธ์ ์ด์ ๊ณผ ๊ฐ์ ํ๊ฒฝ์์ ๋์์ด ๊ฐ๋ฅํฉ๋๋ค. ๋ฐ๋ผ์ ์ดํ์ ๋ค์ด์ค๋ ํจ์ ๋๋ acc ๊ฐ์ ์ผ๋ฐ number ๊ฐ์ด๋ฏ๋ก, while๋ฌธ ์์์ ๊ณ์ ์ฌํ์ฉ ํ๋ฉฐ ์กฐ๊ฑด๋ฌธ์ ๋ง์กฑํ ๋ ๊น์ง ( cur.done ) ์งํ๋ฉ๋๋ค.์ต์ข ์ ์ผ๋ก reduce๋ ์ ์์ ์ผ๋ก acc ๊ฐ 11111๋ก ๊ณ์ฐ๋๊ณ , console.log ํจ์์ ์ํด ๊ทธ ๊ฐ์ด ์ถ๋ ฅ๋ฉ๋๋ค.
- 1
- 4
- 458




