๋ชฉ๋กJavaScript (140)

๐Ÿค ์€์ง€log ๐Ÿค

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค:Javascript] n ๋ฒˆ์งธ ์›์†Œ๋ถ€ํ„ฐ

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค Lv.0 - n ๋ฒˆ์งธ ์›์†Œ๋ถ€ํ„ฐ ๐Ÿ’š ๋ฌธ์ œ์„ค๋ช… ์ •์ˆ˜ ๋ฆฌ์ŠคํŠธ num_list์™€ ์ •์ˆ˜ n์ด ์ฃผ์–ด์งˆ ๋•Œ, n ๋ฒˆ์งธ ์›์†Œ๋ถ€ํ„ฐ ๋งˆ์ง€๋ง‰ ์›์†Œ๊นŒ์ง€์˜ ๋ชจ๋“  ์›์†Œ๋ฅผ ๋‹ด์€ ๋ฆฌ์ŠคํŠธ๋ฅผ returnํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”. ๐Ÿ’š ์ œํ•œ์กฐ๊ฑด 2 ≤ num_list์˜ ๊ธธ์ด ≤ 30 1 ≤ num_list์˜ ์›์†Œ ≤ 9 1 ≤ n ≤ num_list์˜ ๊ธธ์ด ๐Ÿ’š ํ’€์ด function solution(num_list, n) { return num_list.slice(n -1 ) } โœ… slice() ๋ฉ”์†Œ๋“œ ์‚ฌ์šฉํ•ด์•ผ๊ฒ ๋‹ค๊ณ  ์ƒ๊ฐํ•ด์„œ (n) ๋งŒ ๋„ฃ์—ˆ๋”๋‹ˆ n๋ฒˆ์งธ๋Š” ํฌํ•จ์ด ์•ˆ๋˜์–ด์„œ -1 ํ•ด์ฃผ์—ˆ๋‹ค. : n๋ถ€ํ„ฐ ์‹œ์ž‘ํ•˜๋Š” ๋ฐฐ์—ด์˜ ์ผ๋ถ€๋ฅผ ์ถ”์ถœํ•˜๋ ค๋ฉด n - 1์„ ์‚ฌ์šฉํ•˜์—ฌ 0๋ถ€ํ„ฐ ์‹œ์ž‘ํ•˜๋Š” ์ธ๋ฑ์‹ฑ์„ ์กฐ์ •ํ•ด์•ผ ํ•œ๋‹ค. ๐Ÿ’ก slice ๋ฉ”์„œ..

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค:Javascript] ์ •์ˆ˜ ์ฐพ๊ธฐ

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค Lv.0 - ์ •์ˆ˜ ์ฐพ๊ธฐ ๐Ÿ’š ๋ฌธ์ œ์„ค๋ช… ์ •์ˆ˜ ๋ฆฌ์ŠคํŠธ num_list์™€ ์ฐพ์œผ๋ ค๋Š” ์ •์ˆ˜ n์ด ์ฃผ์–ด์งˆ ๋•Œ, num_list์•ˆ์— n์ด ์žˆ์œผ๋ฉด 1์„ ์—†์œผ๋ฉด 0์„ returnํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”. ๐Ÿ’š ์ œํ•œ์กฐ๊ฑด 3 ≤ num_list์˜ ๊ธธ์ด ≤ 100 1 ≤ num_list์˜ ์›์†Œ ≤ 100 1 ≤ n ≤ 100 ๐Ÿ’š ํ’€์ด function solution(num_list, n) { if(num_list.includes(n)){ return 1 } else { return 0 } } โœ… ๋ฐฐ์—ด/ ๋ฌธ์ž์—ด์— ํŠน์ • ๊ฐ’์ด ํฌํ•จ๋˜์–ด์žˆ๋Š”์ง€ ํŒ๋‹จํ•˜๋Š” includes() ์‚ฌ์šฉํ•ด์„œ 1 / 0์„ ๋ฆฌํ„ดํ•ด์•ผ๊ฒ ๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ๋‹ค. ๐Ÿ’ก includes() ๋ฉ”์„œ๋“œ๋Š” ๋ฐฐ์—ด์˜ ํ•ญ๋ชฉ์— ํŠน์ • ๊ฐ’์ด ํฌํ•จ๋˜์–ด ์žˆ๋Š”์ง€๋ฅผ ํŒ๋‹จํ•˜์—ฌ ์ ์ ˆํžˆ..

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค:Javascript] ์ œ๊ณฑ์ˆ˜ ํŒ๋ณ„ํ•˜๊ธฐ

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค Lv.0 - ์ œ๊ณฑ์ˆ˜ ํŒ๋ณ„ํ•˜๊ธฐ ๐Ÿ’š ๋ฌธ์ œ์„ค๋ช… ์–ด๋–ค ์ž์—ฐ์ˆ˜๋ฅผ ์ œ๊ณฑํ–ˆ์„ ๋•Œ ๋‚˜์˜ค๋Š” ์ •์ˆ˜๋ฅผ ์ œ๊ณฑ์ˆ˜๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ์ •์ˆ˜ n์ด ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ, n์ด ์ œ๊ณฑ์ˆ˜๋ผ๋ฉด 1์„ ์•„๋‹ˆ๋ผ๋ฉด 2๋ฅผ returnํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”. ๐Ÿ’š ์ œํ•œ์กฐ๊ฑด 1 ≤ n ≤ 1,000,000 ๐Ÿ’š ํ’€์ด function solution(n) { let x = Math.sqrt(n) if (x % 1 === 0) { return 1 } else { return 2 } } โœ… ์ œ๊ณฑ์ˆ˜์ธ์ง€ ํŒ๋ณ„๋ถ€ํ„ฐ ํ•ด์•ผ๊ฒ ๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ๋‹ค. ๊ฒ€์ƒ‰ํ•ด๋ณด๋‹ˆ Math.sqrt() ํ•จ์ˆ˜๋กœ ์ œ๊ณฑ์ˆ˜๋ฅผ ์ฐพ์„์ˆ˜ ์žˆ๋‹ค๋Š”๊ฒƒ์„ ์•Œ๊ฒŒ๋˜์—ˆ๊ณ  Math.sqrt(n)์œผ๋กœ n์˜ ์ œ๊ณฑ๊ทผ์„ x๋ผ๋Š” ๋ณ€์ˆ˜์— ๋‹ด์•„๋‘”๋’ค, ์กฐ๊ฑด๋ฌธ์œผ๋กœ x๊ฐ€ ์ •์ˆ˜์ธ์ง€ ํŒ๋ณ„ํ•œ๋‹ค. ์ œ๊ณฑ์ˆ˜๊ฐ€ ์•„๋‹ˆ๋ผ๋ฉด ์†Œ์ˆ˜๊ฐ€ ๋‚˜..

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค:Javascript] ๋ฌธ์ž์—ด ๊ณฑํ•˜๊ธฐ

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค Lv.0 - ๋ฌธ์ž์—ด ๊ณฑํ•˜๊ธฐ ๐Ÿ’š ๋ฌธ์ œ์„ค๋ช… ๋ฌธ์ž์—ด my_string๊ณผ ์ •์ˆ˜ k๊ฐ€ ์ฃผ์–ด์งˆ ๋•Œ, my_string์„ k๋ฒˆ ๋ฐ˜๋ณตํ•œ ๋ฌธ์ž์—ด์„ return ํ•˜๋Š” solution ํ•จ์ˆ˜๋ฅผ ์ž‘์„ฑํ•ด ์ฃผ์„ธ์š”. ๐Ÿ’š ์ œํ•œ์กฐ๊ฑด 1 ≤ my_string์˜ ๊ธธ์ด ≤ 100 my_string์€ ์˜์†Œ๋ฌธ์ž๋กœ๋งŒ ์ด๋ฃจ์–ด์ ธ ์žˆ์Šต๋‹ˆ๋‹ค. 1 ≤ k ≤ 100 ๐Ÿ’š ํ’€์ด function solution(my_string, k) { return my_string.repeat(k) } โœ… ์ €๋ฒˆ์— ๋ฌธ์ž์—ด ๋ฐ˜๋ณต์ถœ๋ ฅํ•˜๋Š” ๋ฌธ์ œ์—์„œ ์‚ฌ์šฉํ•œ repeat() ๋ฉ”์„œ๋“œ ์‚ฌ์šฉํ•ด์•ผ๊ฒ ๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ๋‹ค. ๐Ÿ’ก repeat() ๋ฉ”์„œ๋“œ๋Š” ๋ฌธ์ž์—ด์„ ์ฃผ์–ด์ง„ ํšŸ์ˆ˜๋งŒํผ ๋ฐ˜๋ณตํ•ด ๋ถ™์ธ ์ƒˆ๋กœ์šด ๋ฌธ์ž์—ด์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. str.repeat(count); count => ๋ฌธ์ž์—ด์„ ๋ฐ˜๋ณตํ•  ํšŸ์ˆ˜...

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค:Javascript] ์ˆ˜ ์กฐ์ž‘ํ•˜๊ธฐ 1

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค Lv.0 - ์ˆ˜ ์กฐ์ž‘ํ•˜๊ธฐ 1 ๐Ÿ’š ๋ฌธ์ œ์„ค๋ช… ์ •์ˆ˜ n๊ณผ ๋ฌธ์ž์—ด control์ด ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค. control์€ "w", "a", "s", "d"์˜ 4๊ฐœ์˜ ๋ฌธ์ž๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ์œผ๋ฉฐ, control์˜ ์•ž์—์„œ๋ถ€ํ„ฐ ์ˆœ์„œ๋Œ€๋กœ ๋ฌธ์ž์— ๋”ฐ๋ผ n์˜ ๊ฐ’์„ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค. "w" : n์ด 1 ์ปค์ง‘๋‹ˆ๋‹ค. "s" : n์ด 1 ์ž‘์•„์ง‘๋‹ˆ๋‹ค. "d" : n์ด 10 ์ปค์ง‘๋‹ˆ๋‹ค. "a" : n์ด 10 ์ž‘์•„์ง‘๋‹ˆ๋‹ค. ์œ„ ๊ทœ์น™์— ๋”ฐ๋ผ n์„ ๋ฐ”๊ฟจ์„ ๋•Œ ๊ฐ€์žฅ ๋งˆ์ง€๋ง‰์— ๋‚˜์˜ค๋Š” n์˜ ๊ฐ’์„ return ํ•˜๋Š” solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด ์ฃผ์„ธ์š”. ๐Ÿ’š ์ œํ•œ์กฐ๊ฑด -100,000 ≤ n ≤ 100,000 1 ≤ control์˜ ๊ธธ์ด ≤ 100,000 control์€ ์•ŒํŒŒ๋ฒณ ์†Œ๋ฌธ์ž "w", "a", "s", "d"๋กœ ์ด๋ฃจ์–ด์ง„ ๋ฌธ์ž์—ด์ž…๋‹ˆ๋‹ค. ๐Ÿ’š ํ’€์ด funct..