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
- js ๋ฌธ์์ด ์์ถ
- ์๋ฐ์คํฌ๋ฆฝํธ ์ค์ฝํ
- ๋ฐฑ์ค 2108 nodejs
- ๊ตฌ๋ฆํค ์ฑ๋ฆฐ์ง ํ๊ณ
- suspense react-query
- ์ต์ ๋์ฒด์ด๋
- suspense ๋ณ๋ชฉํ์
- suspense ๋์์๋ฆฌ
- js ๊ฑฐ๋ฆฌ๋๊ธฐ ํ์ธํ๊ธฐ
- ๊ตฌ๋ฆํค
- app router emotion
- ํ๋ก๊ทธ๋๋จธ์ค ๋ฌธ์์ด ์์ถ
- ๋ฆฌ์กํธ์ฟผ๋ฆฌ suspense
- ์๋ฐ์คํฌ๋ฆฝํธ ๋ฌธ์์ด ์์ถ
- suspense ๋น๋๊ธฐ
- ํ๋ก๊ทธ๋๋จธ์ค ๊ฑฐ๋ฆฌ๋๊ธฐ ํ์ธํ๊ธฐ
- ๋ฐฑ์ค 1339๋ฒ nodejs
- ๊ตฌ๋ฆํค ์ฑ๋ฆฐ์ง
- emtion app router
- ๋ฐฑ์ค 1339๋ฒ ์๋ฐ์คํฌ๋ฆฝํธ
- next13 emotion
- ๋ฐฑ์ค 1339๋ฒ js
- ์ฌ์ฉ์ฑ ๊ฐ์
- ์ค์ฝํ
- ๋ฐฑ์ค 2108 ์๋ฐ์คํฌ๋ฆฝํธ
- emotion RSC
- TypeError: createContext only works in Client Components. Add the "use client" directive at the top of the file to use it. Read more:
- ์นด์นด์ค ์ฝํ
- js ์ค์ฝํ
- js
Archives
- Today
- Total
Lennon FE
[ํ๋ก๊ทธ๋๋จธ์ค Lv.2] ํํ (js) ๋ณธ๋ฌธ
728x90
๋ฐ์ํ
https://programmers.co.kr/learn/courses/30/lessons/64065?language=javascript
function solution(s) {
let arr = [];
let result = s.replace(/{/gi, "").replace(/}/gi,"").split(",").map((value) => {
arr.push(parseInt(value));
});
arr.sort((a,b) => a - b);
let count = 1;
let obj = [];
for(let i = 0; i < arr.length; i++){
if(arr[i] === arr[i+1]){
count++;
}
else {
obj.push({value : arr[i], count1 : count});
count = 1;
}
}
obj.sort((a,b) => b.count1 - a.count1);
return obj.map((value, index) => {
return value.value;
})
}
s๊ฐ set๋ชจ์ ๋ฌธ์์ด๋ก ์ฃผ์ด์ก๊ธฐ ๋๋ฌธ์ arr์ ๊ฐ ๋ฌธ์๋ฅผ pushํ๋ค.
ex) s = '{{1,2},{1,2,3,4}}' => arr = [1,1,2,2,3,4] ํ์
๋ค์ arr์ ์ ๋ ฌํ๊ณ obj์ ๋์จ ๋ฌธ์ ๋ฐ count๋ฅผ ๊ฐ์ฒดํ์์ผ๋ก pushํ๋ค.
ex) arr = [1,1,2,2,3,4] => obj = [{value: 1, count: 2}, {value: 2, count: 2}, {value: 3, count: 1}, {value: 4, count: 1}]
๋ค์ count๊ฐ ๋ฎ์ ์์ผ๋ก ์ ๋ ฌํ ํ ๋ฐฐ์ดํ์์ผ๋ก ๋ฆฌํดํ๋ฉด ๋!
728x90
๋ฐ์ํ
'๐ฅ Algorithm > Programmers' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํ๋ก๊ทธ๋๋จธ์ค Lv.2] ์ ๊ณ ๊ฒฐ๊ณผ ๋ฐ๊ธฐ(js) (0) | 2022.01.22 |
---|---|
[ํ๋ก๊ทธ๋๋จธ์ค Lv.2] n์ง์ ๊ฒ์(js) (0) | 2022.01.22 |
[ํ๋ก๊ทธ๋๋จธ์ค Lv.2] ์์ ์ฐพ๊ธฐ (js) (0) | 2021.11.12 |
[ํ๋ก๊ทธ๋๋จธ์ค Lv.2] ํ๋ฆฐํฐ (js) (0) | 2021.11.10 |
[ํ๋ก๊ทธ๋๋จธ์ค] ๋ฐฉ๋ฌธ ๊ธธ์ด (js) (0) | 2021.11.08 |
Comments