Notice
Recent Posts
Recent Comments
Link
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- ๋ฆฌ์กํธ์ฟผ๋ฆฌ suspense
- emtion app router
- ๋ฐฑ์ค 2108 ์๋ฐ์คํฌ๋ฆฝํธ
- js
- next13 emotion
- ๋ฐฑ์ค 1339๋ฒ js
- suspense ๋ณ๋ชฉํ์
- emotion RSC
- js ์ค์ฝํ
- suspense react-query
- app router emotion
- ์ฌ์ฉ์ฑ ๊ฐ์
- suspense ๋น๋๊ธฐ
- ๋ฐฑ์ค 2108 nodejs
- ์๋ฐ์คํฌ๋ฆฝํธ ๋ฌธ์์ด ์์ถ
- js ๊ฑฐ๋ฆฌ๋๊ธฐ ํ์ธํ๊ธฐ
- ํ๋ก๊ทธ๋๋จธ์ค ๋ฌธ์์ด ์์ถ
- ์ค์ฝํ
- ๊ตฌ๋ฆํค ์ฑ๋ฆฐ์ง
- ์นด์นด์ค ์ฝํ
- TypeError: createContext only works in Client Components. Add the "use client" directive at the top of the file to use it. Read more:
- ๋ฐฑ์ค 1339๋ฒ ์๋ฐ์คํฌ๋ฆฝํธ
- ์ต์ ๋์ฒด์ด๋
- ํ๋ก๊ทธ๋๋จธ์ค ๊ฑฐ๋ฆฌ๋๊ธฐ ํ์ธํ๊ธฐ
- ์๋ฐ์คํฌ๋ฆฝํธ ์ค์ฝํ
- ๊ตฌ๋ฆํค
- ๋ฐฑ์ค 1339๋ฒ nodejs
- suspense ๋์์๋ฆฌ
- ๊ตฌ๋ฆํค ์ฑ๋ฆฐ์ง ํ๊ณ
- js ๋ฌธ์์ด ์์ถ
Archives
- Today
- Total
Lennon FE
[ํ๋ก๊ทธ๋๋จธ์ค] ๋ฒ ์คํธ์จ๋ฒ (js) ๋ณธ๋ฌธ
728x90
๋ฐ์ํ
https://programmers.co.kr/learn/courses/30/lessons/42579?language=javascript
function solution(genres, plays) {
const set = new Set(genres);
const UniqueGenres = [...set];
const playCount = UniqueGenres.map((v) => {
const play = genres.reduce((prev,cur,idx) => {
if(cur === v) prev += plays[idx];
return prev;
},0)
return [v, play];
})
playCount.sort((a,b) => b[1]-a[1]);
const genresPlays = genres.map((v, i) => [v, plays[i], i])
genresPlays.sort((a,b) => b[1]-a[1]);
let answer = [];
for(let i = 0; i < playCount.length; i++){
let count = 0;
for(let j = 0; j < genresPlays.length; j++){
if(playCount[i][0] === genresPlays[j][0]){
count++;
answer.push(genresPlays[j][2]);
if(count===2) break;
}
}
}
return answer;
}
ํด์ ์๊ณ ๋ฆฌ์ฆ ๋ฌธ์ ์ด๋ค.
์ฒ์์ reduce, map์ ์ด์ฉํ์ฌ ํ์์ง๋ง, ๋ง์๋ ์ฅ๋ฅด๋ณ ๋ง์ด ์ฌ์๋ ์์ 2๊ฐ๋ง ์ฐพ์ผ๋ฉด ๋๊ธฐ๋๋ฌธ์
ํจ์จ์ ์ผ๋ก ๋์ํ ์ ์๋๋ก break๋ฅผ ๊ฑธ ์ ์๊ฒ for๋ฌธ์ ์ด์ฉํ์๋ค.
728x90
๋ฐ์ํ
'๐ฅ Algorithm > Programmers' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํ๋ก๊ทธ๋๋จธ์ค] (1์ฐจ) ๋ด์ค ํด๋ฌ์คํฐ๋ง (js) (0) | 2021.10.27 |
---|---|
[ํ๋ก๊ทธ๋๋จธ์ค] ์ํด๋ฆฌ์ฑ๋ฆฐ์ง 12์ฃผ์ฐจ (js) (0) | 2021.10.26 |
[ํ๋ก๊ทธ๋๋จธ์ค] ๊ฐ์ฅ ํฐ ์ (js) (0) | 2021.10.25 |
[ํ๋ก๊ทธ๋๋จธ์ค] ๊ธฐ๋ฅ ๊ฐ๋ฐ (js) (0) | 2021.10.25 |
[ํ๋ก๊ทธ๋๋จธ์ค] ํฌ๋ ์ธ ์ธํ๋ฝ๊ธฐ (javascript) (0) | 2021.10.20 |
Comments