๋ฐ˜์‘ํ˜•

ํ”„๋ก ํŠธ์—”๋“œ 22

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/JS] ์™ธ๊ณ„ํ–‰์„ฑ์˜ ๋‚˜์ด

Problem Description. ์šฐ์ฃผ์—ฌํ–‰์„ ํ•˜๋˜ ๋จธ์“ฑ์ด๋Š” ์—”์ง„ ๊ณ ์žฅ์œผ๋กœ PROGRAMMERS-962 ํ–‰์„ฑ์— ๋ถˆ์‹œ์ฐฉํ•˜๊ฒŒ ๋์Šต๋‹ˆ๋‹ค. ์ž…๊ตญ์‹ฌ์‚ฌ์—์„œ ๋‚˜์ด๋ฅผ ๋งํ•ด์•ผ ํ•˜๋Š”๋ฐ, PROGRAMMERS-962 ํ–‰์„ฑ์—์„œ๋Š” ๋‚˜์ด๋ฅผ ์•ŒํŒŒ๋ฒณ์œผ๋กœ ๋งํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. a๋Š” 0, b๋Š” 1, c๋Š” 2, ..., j๋Š” 9์ž…๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด 23์‚ด์€ cd, 51์‚ด์€ fb๋กœ ํ‘œํ˜„ํ•ฉ๋‹ˆ๋‹ค. ๋‚˜์ด age๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ PROGRAMMER-962์‹ ๋‚˜์ด๋ฅผ returnํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”. Restrictions. age๋Š” ์ž์—ฐ์ˆ˜์ž…๋‹ˆ๋‹ค. age ≤ 1,000 PROGRAMMERS-962 ํ–‰์„ฑ์€ ์•ŒํŒŒ๋ฒณ ์†Œ๋ฌธ์ž๋งŒ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. Input/Output Example. age result 23 "cd" 51 "fb" 100..

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/JS] ๋ฌธ์ž์—ด ์ •๋ ฌํ•˜๊ธฐ (1)

Problem Description ๋ฌธ์ž์—ด my_string์ด ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ, my_string ์•ˆ์— ์žˆ๋Š” ์ˆซ์ž๋งŒ ๊ณจ๋ผ ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌํ•œ ๋ฆฌ์ŠคํŠธ๋ฅผ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์ž‘์„ฑํ•ด๋ณด์„ธ์š”. Restrictions. 1 ≤ my_string์˜ ๊ธธ์ด ≤ 100 my_string์—๋Š” ์ˆซ์ž๊ฐ€ ํ•œ ๊ฐœ ์ด์ƒ ํฌํ•จ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. my_string์€ ์˜์–ด ์†Œ๋ฌธ์ž ๋˜๋Š” 0๋ถ€ํ„ฐ 9๊นŒ์ง€์˜ ์ˆซ์ž๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ์Šต๋‹ˆ๋‹ค. - - - Input/Output Example ์ž…์ถœ๋ ฅ ์˜ˆ #1 "hi12392"์— ์žˆ๋Š” ์ˆซ์ž 1, 2, 3, 9, 2๋ฅผ ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌํ•œ [1, 2, 2, 3, 9]๋ฅผ return ํ•ฉ๋‹ˆ๋‹ค. ์ž…์ถœ๋ ฅ ์˜ˆ #2 "p2o4i8gj2"์— ์žˆ๋Š” ์ˆซ์ž 2, 4, 8, 2๋ฅผ ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌํ•œ [2, 2, 4,..

[React] React Hook "useSelector" cannot be called inside a callback ์—๋Ÿฌ ๋ฐ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•

Intro ์•ˆ๋…•ํ•˜์„ธ์š”. react hook useSelector ๋ฅผ ์‚ฌ์šฉํ•˜๋˜ ๋„์ค‘ ์•„๋ž˜์˜ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค. React Hook "useSelector" cannot be called inside a callback function YourComponent() { useEffect(() => { useSelector((state: RootState) => state.code[SOME_DATA]) }, []) } Why? react hook์„ ์‚ฌ์šฉํ•  ๋•Œ๋Š” ์ค‘์š”ํ•œ 2๊ฐ€์ง€ ๊ทœ์น™์ด ์žˆ์Šต๋‹ˆ๋‹ค. 1๏ธโƒฃ Only Call Hooks at the Top Level ๋ฃจํ”„ ์กฐ๊ฑด ๋˜๋Š” ์ค‘์ฒฉ๋œ ํ•จ์ˆ˜ ๋‚ด์—์„œ Hooks๋ฅผ ํ˜ธ์ถœํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. ํ•ญ์ƒ React ํ•จ์ˆ˜์˜ Top Level์—์„œ Hooks๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์ด ๊ทœ์น™์„..

Framework/React 2023.09.18

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/JS] ๊ฐ€์œ„ ๋ฐ”์œ„ ๋ณด

Problem Description ๊ฐ€์œ„๋Š” 2 ๋ฐ”์œ„๋Š” 0 ๋ณด๋Š” 5๋กœ ํ‘œํ˜„ํ•ฉ๋‹ˆ๋‹ค. ๊ฐ€์œ„ ๋ฐ”์œ„ ๋ณด๋ฅผ ๋‚ด๋Š” ์ˆœ์„œ๋Œ€๋กœ ๋‚˜ํƒ€๋‚ธ ๋ฌธ์ž์—ด rsp๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ, rsp์— ์ €์žฅ๋œ ๊ฐ€์œ„ ๋ฐ”์œ„ ๋ณด๋ฅผ ๋ชจ๋‘ ์ด๊ธฐ๋Š” ๊ฒฝ์šฐ๋ฅผ ์ˆœ์„œ๋Œ€๋กœ ๋‚˜ํƒ€๋‚ธ ๋ฌธ์ž์—ด์„ returnํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด๋ณด์„ธ์š”. Restrictions. 0 < rsp์˜ ๊ธธ์ด ≤ 100 rsp์™€ ๊ธธ์ด๊ฐ€ ๊ฐ™์€ ๋ฌธ์ž์—ด์„ return ํ•ฉ๋‹ˆ๋‹ค. rsp๋Š” ์ˆซ์ž 0, 2, 5๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ์Šต๋‹ˆ๋‹ค. Input/Output Example ์ž…์ถœ๋ ฅ ์˜ˆ #1 "2"๋Š” ๊ฐ€์œ„์ด๋ฏ€๋กœ ๋ฐ”์œ„๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” "0"์„ return ํ•ฉ๋‹ˆ๋‹ค. ์ž…์ถœ๋ ฅ ์˜ˆ #2 "205"๋Š” ์ˆœ์„œ๋Œ€๋กœ ๊ฐ€์œ„, ๋ฐ”์œ„, ๋ณด์ด๊ณ  ์ด๋ฅผ ๋ชจ๋‘ ์ด๊ธฐ๋ ค๋ฉด ๋ฐ”์œ„, ๋ณด, ๊ฐ€์œ„๋ฅผ ์ˆœ์„œ๋Œ€๋กœ ๋‚ด์•ผํ•˜๋ฏ€๋กœ “052”๋ฅผ returnํ•ฉ..

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/JS] ๋Œ€๋ฌธ์ž์™€ ์†Œ๋ฌธ์ž

Problem Description ๋ฌธ์ž์—ด my_string์ด ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ, ๋Œ€๋ฌธ์ž๋Š” ์†Œ๋ฌธ์ž๋กœ ์†Œ๋ฌธ์ž๋Š” ๋Œ€๋ฌธ์ž๋กœ ๋ณ€ํ™˜ํ•œ ๋ฌธ์ž์—ด์„ returnํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”. Restrictions 1 ≤ my_string์˜ ๊ธธ์ด ≤ 1,000 my_string์€ ์˜์–ด ๋Œ€๋ฌธ์ž์™€ ์†Œ๋ฌธ์ž๋กœ๋งŒ ๊ตฌ์„ฑ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. Input/Output Example ์ž…์ถœ๋ ฅ ์˜ˆ # 1 ์†Œ๋ฌธ์ž๋Š” ๋Œ€๋ฌธ์ž๋กœ ๋Œ€๋ฌธ์ž๋Š” ์†Œ๋ฌธ์ž๋กœ ๋ฐ”๊พผ "CCCccc"๋ฅผ returnํ•ฉ๋‹ˆ๋‹ค. ์ž…์ถœ๋ ฅ ์˜ˆ #2 ์†Œ๋ฌธ์ž๋Š” ๋Œ€๋ฌธ์ž๋กœ ๋Œ€๋ฌธ์ž๋Š” ์†Œ๋ฌธ์ž๋กœ ๋ฐ”๊พผ "ABcDeFGHij"๋ฅผ returnํ•ฉ๋‹ˆ๋‹ค. My solution function solution(my_string) { return my_string.split("").map((x) => x ..

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/JS] ์ˆจ์–ด์žˆ๋Š” ์ˆซ์ž์˜ ๋ง์…ˆ (1)

Problem Description ๋ฌธ์ž์—ด my_string์ด ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค. my_string์•ˆ์˜ ๋ชจ๋“  ์ž์—ฐ์ˆ˜๋“ค์˜ ํ•ฉ์„ returnํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”. Restrictions 1 ≤ my_string์˜ ๊ธธ์ด ≤ 1,000 my_string์€ ์†Œ๋ฌธ์ž, ๋Œ€๋ฌธ์ž ๊ทธ๋ฆฌ๊ณ  ํ•œ์ž๋ฆฌ ์ž์—ฐ์ˆ˜๋กœ๋งŒ ๊ตฌ์„ฑ๋˜์–ด์žˆ์Šต๋‹ˆ๋‹ค. Input/Output Example ์ž…์ถœ๋ ฅ ์˜ˆ # "aAb1B2cC34oOp"์•ˆ์˜ ํ•œ์ž๋ฆฌ ์ž์—ฐ์ˆ˜๋Š” 1, 2, 3, 4 ์ž…๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ 1 + 2 + 3 + 4 = 10 ์„ returnํ•ฉ๋‹ˆ๋‹ค. ์ž…์ถœ๋ ฅ ์˜ˆ #2 "1a2b3c4d123Z"์•ˆ์˜ ํ•œ์ž๋ฆฌ ์ž์—ฐ์ˆ˜๋Š” 1, 2, 3, 4, 1, 2, 3 ์ž…๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ 1 + 2 + 3 + 4 + 1 + 2 + 3 = 16 ์„ returnํ•ฉ..

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/JS] ํ”ผ์ž ๋‚˜๋ˆ  ๋จน๊ธฐ (1)

Problem Description ๋จธ์“ฑ์ด๋„ค ํ”ผ์ž๊ฐ€๊ฒŒ๋Š” ํ”ผ์ž๋ฅผ ์ผ๊ณฑ ์กฐ๊ฐ์œผ๋กœ ์ž˜๋ผ ์ค๋‹ˆ๋‹ค. ํ”ผ์ž๋ฅผ ๋‚˜๋ˆ ๋จน์„ ์‚ฌ๋žŒ์˜ ์ˆ˜ n์ด ์ฃผ์–ด์งˆ ๋•Œ, ๋ชจ๋“  ์‚ฌ๋žŒ์ด ํ”ผ์ž๋ฅผ ํ•œ ์กฐ๊ฐ ์ด์ƒ ๋จน๊ธฐ ์œ„ํ•ด ํ•„์š”ํ•œ ํ”ผ์ž์˜ ์ˆ˜๋ฅผ return ํ•˜๋Š” solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด๋ณด์„ธ์š”. Restrictions 1 ≤ n ≤ 100 Input/Output Example ์ž…์ถœ๋ ฅ ์˜ˆ #1 7๋ช…์ด ์ตœ์†Œ ํ•œ ์กฐ๊ฐ์”ฉ ๋จน๊ธฐ ์œ„ํ•ด์„œ ์ตœ์†Œ 1ํŒ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. ์ž…์ถœ๋ ฅ ์˜ˆ #2 1๋ช…์€ ์ตœ์†Œ ํ•œ ์กฐ๊ฐ์„ ๋จน๊ธฐ ์œ„ํ•ด 1ํŒ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. ์ž…์ถœ๋ ฅ ์˜ˆ #2 15๋ช…์ด ์ตœ์†Œ ํ•œ ์กฐ๊ฐ์”ฉ ๋จน๊ธฐ ์œ„ํ•ด์„œ ์ตœ์†Œ 3ํŒ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. My solution function solution(n) { if ((n % 7) >= 0) { return Math.ceil(n/7) } } An..

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/JS] ๋ฌธ์ž ๋ฐ˜๋ณต ์ถœ๋ ฅํ•˜๊ธฐ

Problem Description ๋ฌธ์ž์—ด my_string๊ณผ ์ •์ˆ˜ n์ด ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ, my_string์— ๋“ค์–ด์žˆ๋Š” ๊ฐ ๋ฌธ์ž๋ฅผ n๋งŒํผ ๋ฐ˜๋ณตํ•œ ๋ฌธ์ž์—ด์„ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด๋ณด์„ธ์š”. Restrictions 2 ≤ my_string ๊ธธ์ด ≤ 5 2 ≤ n ≤ 10 "my_string"์€ ์˜์–ด ๋Œ€์†Œ๋ฌธ์ž๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ์Šต๋‹ˆ๋‹ค. Input/Output Example ์ž…์ถœ๋ ฅ ์˜ˆ #1 "hello"์˜ ๊ฐ ๋ฌธ์ž๋ฅผ ์„ธ ๋ฒˆ์”ฉ ๋ฐ˜๋ณตํ•œ "hhheeellllllooo"๋ฅผ return ํ•ฉ๋‹ˆ๋‹ค. My solution function solution(my_string, n) { return (my_string.split("").map((x) => x.repeat(n))).join('') } Anot..

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/JS] ์ง์ˆ˜ ํ™€์ˆ˜ ๊ฐœ์ˆ˜

Problem Description์ •์ˆ˜๊ฐ€ ๋‹ด๊ธด ๋ฆฌ์ŠคํŠธ num_list๊ฐ€ ์ฃผ์–ด์งˆ ๋•Œ, num_list์˜ ์›์†Œ ์ค‘ ์ง์ˆ˜์™€ ํ™€์ˆ˜์˜ ๊ฐœ์ˆ˜๋ฅผ ๋‹ด์€ ๋ฐฐ์—ด์„ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด๋ณด์„ธ์š”. Restrictions1 ≤ num_list์˜ ๊ธธ์ด ≤ 1000 ≤ num_list์˜ ์›์†Œ ≤ 1,000 Input/Output Example์ž…์ถœ๋ ฅ ์˜ˆ #1 [1, 2, 3, 4, 5]์—๋Š” ์ง์ˆ˜๊ฐ€ 2, 4๋กœ ๋‘ ๊ฐœ, ํ™€์ˆ˜๊ฐ€ 1, 3, 5๋กœ ์„ธ ๊ฐœ ์žˆ์Šต๋‹ˆ๋‹ค.์ž…์ถœ๋ ฅ ์˜ˆ #2 [1, 3, 5, 7]์—๋Š” ์ง์ˆ˜๊ฐ€ ์—†๊ณ  ํ™€์ˆ˜๊ฐ€ ๋„ค ๊ฐœ ์žˆ์Šต๋‹ˆ๋‹ค. My solutionfunction solution(num_list) {    let result = []    const even = num_list.filter((x) =..

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/JS] ๋ฐฐ์—ด ์ž๋ฅด๊ธฐ

Problem Description ์ •์ˆ˜ ๋ฐฐ์—ด numbers์™€ ์ •์ˆ˜ num1, num2๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ, numbers์˜ num1๋ฒˆ ์งธ ์ธ๋ฑ์Šค๋ถ€ํ„ฐ num2๋ฒˆ์งธ ์ธ๋ฑ์Šค๊นŒ์ง€ ์ž๋ฅธ ์ •์ˆ˜ ๋ฐฐ์—ด์„ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด๋ณด์„ธ์š”. Restrictions 2 ≤ numbers์˜ ๊ธธ์ด ≤ 30 0 ≤ numbers์˜ ์›์†Œ ≤ 1,000 0 ≤num1

๋ฐ˜์‘ํ˜•