๋ชฉ๋กJavaScript (140)

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

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

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค Lv.0 - ์›ํ•˜๋Š” ๋ฌธ์ž์—ด ์ฐพ๊ธฐ ๐Ÿ’š ๋ฌธ์ œ์„ค๋ช… ์•ŒํŒŒ๋ฒณ์œผ๋กœ ์ด๋ฃจ์–ด์ง„ ๋ฌธ์ž์—ด myString๊ณผ pat์ด ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค. myString์˜ ์—ฐ์†๋œ ๋ถ€๋ถ„ ๋ฌธ์ž์—ด ์ค‘ pat์ด ์กด์žฌํ•˜๋ฉด 1์„ ๊ทธ๋ ‡์ง€ ์•Š์œผ๋ฉด 0์„ return ํ•˜๋Š” solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด ์ฃผ์„ธ์š”. ๋‹จ, ์•ŒํŒŒ๋ฒณ ๋Œ€๋ฌธ์ž์™€ ์†Œ๋ฌธ์ž๋Š” ๊ตฌ๋ถ„ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ๐Ÿ’š ์ œํ•œ์กฐ๊ฑด 1 ≤ myString์˜ ๊ธธ์ด ≤ 100,000 1 ≤ pat์˜ ๊ธธ์ด ≤ 300 myString๊ณผ pat์€ ๋ชจ๋‘ ์•ŒํŒŒ๋ฒณ์œผ๋กœ ์ด๋ฃจ์–ด์ง„ ๋ฌธ์ž์—ด์ž…๋‹ˆ๋‹ค. ๐Ÿ’š ํ’€์ด function solution(myString, pat) { if(myString.toUpperCase().includes(pat.toUpperCase())){ return 1 } else { return 0 } } โœ… ์ฒ˜์Œ์—๋Š”..

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค:Javascript] ์ ‘๋ฏธ์‚ฌ์ธ์ง€ ํ™•์ธํ•˜๊ธฐ

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค Lv.0 - ์ ‘๋ฏธ์‚ฌ์ธ์ง€ ํ™•์ธํ•˜๊ธฐ ๐Ÿ’š ๋ฌธ์ œ์„ค๋ช… ์–ด๋–ค ๋ฌธ์ž์—ด์— ๋Œ€ํ•ด์„œ ์ ‘๋ฏธ์‚ฌ๋Š” ํŠน์ • ์ธ๋ฑ์Šค๋ถ€ํ„ฐ ์‹œ์ž‘ํ•˜๋Š” ๋ฌธ์ž์—ด์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, "banana"์˜ ๋ชจ๋“  ์ ‘๋ฏธ์‚ฌ๋Š” "banana", "anana", "nana", "ana", "na", "a"์ž…๋‹ˆ๋‹ค. ๋ฌธ์ž์—ด my_string๊ณผ is_suffix๊ฐ€ ์ฃผ์–ด์งˆ ๋•Œ, is_suffix๊ฐ€ my_string์˜ ์ ‘๋ฏธ์‚ฌ๋ผ๋ฉด 1์„, ์•„๋‹ˆ๋ฉด 0์„ return ํ•˜๋Š” solution ํ•จ์ˆ˜๋ฅผ ์ž‘์„ฑํ•ด ์ฃผ์„ธ์š”. ๐Ÿ’š ์ œํ•œ์กฐ๊ฑด 1 ≤ my_string์˜ ๊ธธ์ด ≤ 100 1 ≤ is_suffix์˜ ๊ธธ์ด ≤ 100 my_string๊ณผ is_suffix๋Š” ์˜์†Œ๋ฌธ์ž๋กœ๋งŒ ์ด๋ฃจ์–ด์ ธ ์žˆ์Šต๋‹ˆ๋‹ค. ๐Ÿ’š ํ’€์ด function solution(my_string, is_suffix) { retu..

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค:Javascript] n์˜ ๋ฐฐ์ˆ˜ ๊ณ ๋ฅด๊ธฐ

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค Lv.0 - n์˜ ๋ฐฐ์ˆ˜ ๊ณ ๋ฅด๊ธฐ ๐Ÿ’š ๋ฌธ์ œ์„ค๋ช… ์ •์ˆ˜ n๊ณผ ์ •์ˆ˜ ๋ฐฐ์—ด numlist๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ, numlist์—์„œ n์˜ ๋ฐฐ์ˆ˜๊ฐ€ ์•„๋‹Œ ์ˆ˜๋“ค์„ ์ œ๊ฑฐํ•œ ๋ฐฐ์—ด์„ returnํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”. ๐Ÿ’š ์ œํ•œ์กฐ๊ฑด 1 ≤ n ≤ 10,000 1 ≤ numlist์˜ ํฌ๊ธฐ ≤ 100 1 ≤ numlist์˜ ์›์†Œ ≤ 100,000 ๐Ÿ’š ํ’€์ด function solution(n, numlist) { return numlist.filter((i) => i % n === 0) } โœ… n์˜ ๋ฐฐ์ˆ˜๋ฅผ ๋จผ์ € ์ฐพ์•„์•ผ๊ฒ ๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ๋‹ค. ๋ฐฐ์—ด์—์„œ n์œผ๋กœ ๋‚˜๋ˆ„์—ˆ์„๋•Œ ๋‚˜๋จธ์ง€๊ฐ€ 0์ด๋ฉด ๋ฐฐ์ˆ˜์ด๋‹ˆ๊นŒ filter()๋ฉ”์„œ๋“œ๋กœ i % n === 0 ์กฐ๊ฑด์„ ํ™•์ธํ•˜๊ณ , ๋‚˜๋ˆ„์–ด ๋–จ์–ด์ง€๋Š” ๊ฒฝ์šฐ์—๋งŒ true๋ฅผ ๋ฐ˜ํ™˜ํ•˜์—ฌ ํ•ด๋‹น ์š”..

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค:Javascript] ๋ถ€๋ถ„ ๋ฌธ์ž์—ด

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค Lv.0 - ๋ถ€๋ถ„ ๋ฌธ์ž์—ด ๐Ÿ’š ๋ฌธ์ œ์„ค๋ช… ์–ด๋–ค ๋ฌธ์ž์—ด A๊ฐ€ ๋‹ค๋ฅธ ๋ฌธ์ž์—ด B์•ˆ์— ์†ํ•˜๋ฉด A๋ฅผ B์˜ ๋ถ€๋ถ„ ๋ฌธ์ž์—ด์ด๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด ๋ฌธ์ž์—ด "abc"๋Š” ๋ฌธ์ž์—ด "aabcc"์˜ ๋ถ€๋ถ„ ๋ฌธ์ž์—ด์ž…๋‹ˆ๋‹ค. ๋ฌธ์ž์—ด str1๊ณผ str2๊ฐ€ ์ฃผ์–ด์งˆ ๋•Œ, str1์ด str2์˜ ๋ถ€๋ถ„ ๋ฌธ์ž์—ด์ด๋ผ๋ฉด 1์„ ๋ถ€๋ถ„ ๋ฌธ์ž์—ด์ด ์•„๋‹ˆ๋ผ๋ฉด 0์„ returnํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”. ๐Ÿ’š ์ œํ•œ์กฐ๊ฑด 1 ≤ str1 ≤ str2 ≤ 20 str1๊ณผ str2๋Š” ์˜์–ด ์†Œ๋ฌธ์ž๋กœ๋งŒ ์ด๋ฃจ์–ด์ ธ ์žˆ์Šต๋‹ˆ๋‹ค. ๐Ÿ’š ํ’€์ด function solution(str1, str2) { if ( str2.includes(str1)) { return 1 } else { return 0 } } โœ… ๐Ÿ’ก includes() ๋ฉ”์„œ๋“œ๋Š” ํ•˜๋‚˜์˜ ๋ฌธ์ž์—ด์ด ๋‹ค๋ฅธ ..

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค:Javascript] ๋ถ€๋ถ„ ๋ฌธ์ž์—ด์ธ์ง€ ํ™•์ธํ•˜๊ธฐ

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค Lv.0 - ๋ถ€๋ถ„ ๋ฌธ์ž์—ด์ธ์ง€ ํ™•์ธํ•˜๊ธฐ ๐Ÿ’š ๋ฌธ์ œ์„ค๋ช… ๋ถ€๋ถ„ ๋ฌธ์ž์—ด์ด๋ž€ ๋ฌธ์ž์—ด์—์„œ ์—ฐ์†๋œ ์ผ๋ถ€๋ถ„์— ํ•ด๋‹นํ•˜๋Š” ๋ฌธ์ž์—ด์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ๋ฌธ์ž์—ด "ana", "ban", "anana", "banana", "n"๋Š” ๋ชจ๋‘ ๋ฌธ์ž์—ด "banana"์˜ ๋ถ€๋ถ„ ๋ฌธ์ž์—ด์ด์ง€๋งŒ, "aaa", "bnana", "wxyz"๋Š” ๋ชจ๋‘ "banana"์˜ ๋ถ€๋ถ„ ๋ฌธ์ž์—ด์ด ์•„๋‹™๋‹ˆ๋‹ค. ๋ฌธ์ž์—ด my_string๊ณผ target์ด ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ, target์ด ๋ฌธ์ž์—ด my_string์˜ ๋ถ€๋ถ„ ๋ฌธ์ž์—ด์ด๋ผ๋ฉด 1์„, ์•„๋‹ˆ๋ผ๋ฉด 0์„ return ํ•˜๋Š” solution ํ•จ์ˆ˜๋ฅผ ์ž‘์„ฑํ•ด ์ฃผ์„ธ์š”. ๐Ÿ’š ์ œํ•œ์กฐ๊ฑด 1 ≤ my_string์˜ ๊ธธ์ด ≤ 100 my_string์€ ์˜์†Œ๋ฌธ์ž๋กœ๋งŒ ์ด๋ฃจ์–ด์ ธ ์žˆ์Šต๋‹ˆ๋‹ค. 1 ≤ target์˜ ๊ธธ์ด ≤ 100 ..