Posts
Q&A
์ธ์คํด์ค ์์ฑ
์, ์ ๊ฐ ์คํด๋ฅผ ํ๋ ๋ด ๋๋ค. constructor๋ด์ ()๋ฅผ ๋ถ์ด์ง ์๊ณ ์ฝ๋ฉ์ ํ์๊ณ ์ค๋ฅ ์์ด ์คํ์ด ๋์๋๋ฐ, testํ์ผ์์๋ ()๋ฅผ ๋ถ์ด์ง ์์ผ๋ฉด ์คํ์ด ๋์ง ์์๋๋ฐ ์๋ฌธ์ ์์ธํ ์ดํผ์ง ์์๋ค์. ์ฌํ์ธํด๋ณด๋ ์ ๋ถ ()๋ฅผ ๋ถ์ฌ์ ์จ์ฃผ์ จ์ด์. ๊ฐ์๋, ๋น ๋ฅธ ๋ต๋ณ ๊ฐ์ฌ๋๋ฆฝ๋๋ค.
- 1
- 2
- 478
Q&A
Test_queue ์ถ๋ ฅ ์ค๋ฅ
์ ๋ ๋น์ทํ ์ค๋ฅ๊ฐ ์์ด์ ๋ต๊ธ ๋จ๊น๋๋ค.์ด๋ฏธ ํด๊ฒฐํ์ จ๋์ง ๋ชจ๋ฅด๊ฒ ์ผ๋, this.head๊ฐ null์ด ์๋ ๋ newNode๋ฅผ this.head์ ์๋ ธ๋๋ก ์ง์ ํด์ฃผ๋ ๊ตฌ๋ฌธ ( if๋ฌธ์์ ์ค์ )์ ์์ ํ์๋ฉด ๋ ๊ฑฐ ๊ฐ์์. if(index == 0) { newNode.next = this.head; if(this.head !=null) { this.head.prev = newNode; }
- 1
- 2
- 511
Q&A
Promis์ค์ต ๋์ค์ ์๋ฌ๋ฉ์์ง
๋น ๋ฅธ ๋ต๋ณ ๊ฐ์ฌํฉ๋๋ค. ์ ๊ฐ ์ฌ๋ฌ๋ฒ ํ ์คํธํ๋ฉด์ ๊ธ์ ์ฌ๋ฆฌ๋ค ๋ณด๋ ์ด์ ๊ธ์ ๊ฐ์ฌ๋์ด ๋ต๋ณ์ฃผ์ ๋ด์ฉ์ด ์ญ์ ๋์ด, ๋ค๋ฅธ๋ถ๋ค๊ป๋ ์ฐธ์กฐ๊ฐ ๋์ค๊น ํ์ฌ ์ฌ๋ ค๋ด ๋๋ค. ์ ๋ Postman Mockserver์์ ์๋ถ๋ถ๋ง ๋จผ์ ๋ฃ๊ณ JSON์ผ๋ก ๋ง๋ค์ด์ ํด๋น ๋ด์ฉ์ API๋ก ๋ณด๋ด๊ณ , Promise๋ถ๋ถ ์์ ์ ์งํํด์ ์ค์๊ฐ ์์๋ค์ (Productsํ๋จ์ Array๋ฐฐ์ด). ๊ฐ์ฌ๋์ mockserver์์ ๋ท๋ถ๋ถ์ ๊ฐ์ฒด ๊ตฌ์ฑ์ผ๋ก ์ธํ ์ค๋ฅ์์ ์ด ์์ต๋๋ค. ์ด๊ธฐ์ ์ค๋ฅ๋ ์๋์ ๊ฐ์์ต๋๋ค.resolve(response.data)๋ก ์๋ฃ๋ฅผ ๋ฐ์์๋ console์ ์ค๋ฅ์ ๋๋ค. productsํ๋จ์ ์ด๋ ์ด๊ฐ ๋ฐฐ์ด๋ฉ๋๋ค. ์ฝ์์ ๋ณด์๋ฉด ํ์ธ๋ฉ๋๋ค.(์ฌ์ง)๊ฐ์ฌ๋์ด ์๋ ค์ฃผ์ ๋๋ก resolve(response.data.products)๋ก ํ์์ต๋๋ค. axios์์ ๋ฐ์์จ ์๋ฃ๋ก data๋ฅผ ์ถ๋ ฅํ๋ productsํ๋จ์ ์๋ฃํ์ด ๋ฐ์์ง๊ณ , ์ดํ resolve๋ก ๋ฐ์์ง ์๋ฃ๋ (ํฉ๊ณ๋ฅผ ๋ด๋ ํจ์๋ด์์๋) ์ด๋ ์ด๋ก ๋ฐ์์ง ๊ฒ์ด ํ์ธ๋ฉ๋๋ค. console.log๋ก ์ธ๋ถ๊ฐ์ ํ์ธํ๋ฉด์ ์งํํ์์ต๋๋ค. ( ์ ๋ Price๋ฅผ ๋๋ฌธ์๋ก ์ง์ ํ์ฌ, item.Price๋ก ํด์ผ ๊ณ์ฐ์ด ๋์์ต๋๋ค.) Document url ="https://3f5ea77d-8b64-48bb-ad04-fc87ad96cab4.mock.pstmn.io/productList" function getData(){ return new Promise(function(resolve, reject){ axios.get(url).then(function(response){ console.log(response.data); resolve(response.data.products); }); }); } var total=0; getData().then(function(data){ console.log(data) for (var item of data){ console.log(item.Price) total += item.Price; } console.log(total) }) (์ฌ์ง)
- 0
- 2
- 416
Q&A
๊ฐ์์๋ฃ ์์ฒญ๋๋ฆฝ๋๋ค.
๊ฐ์ฌํฉ๋๋ค~ ์ข์ ๊ฐ์ ๋ ๋ง์ด ์ ์ํด์ฃผ์ จ์ผ๋ฉด ์ข๊ฒ ์ต๋๋ค.
- 1
- 3
- 283