๋ชฉ๋กJavaScript (140)

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

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค:Javascript] ๋ชจ์Œ ์ œ๊ฑฐ

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค Lv.0 - ๋ชจ์Œ ์ œ๊ฑฐ ๐Ÿ’š ๋ฌธ์ œ์„ค๋ช… ์˜์–ด์—์„  a, e, i, o, u ๋‹ค์„ฏ ๊ฐ€์ง€ ์•ŒํŒŒ๋ฒณ์„ ๋ชจ์Œ์œผ๋กœ ๋ถ„๋ฅ˜ํ•ฉ๋‹ˆ๋‹ค. ๋ฌธ์ž์—ด my_string์ด ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ ๋ชจ์Œ์„ ์ œ๊ฑฐํ•œ ๋ฌธ์ž์—ด์„ returnํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”. ๐Ÿ’š ์ œํ•œ์กฐ๊ฑด my_string์€ ์†Œ๋ฌธ์ž์™€ ๊ณต๋ฐฑ์œผ๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ์Šต๋‹ˆ๋‹ค. 1 ≤ my_string์˜ ๊ธธ์ด ≤ 1,000 ๐Ÿ’š ํ’€์ด function solution(my_string) { const answer = my_string.replace(/a|e|i|o|u/g,"") return answer; } โœ… ๋ฌธ์ž์—ด์—์„œ a,e,i,o,u ๋งŒ ์ œ๊ฑฐํ•˜๊ธฐ replace() ์‚ฌ์šฉํ•ด์•ผํ•˜๋Š”๊ฑด ์•Œ์•˜๋Š”๋ฐ ๋ชจ์Œ”๋“ค” ์„ ๋‹ค ๋„ฃ๋Š” ๋ฐฉ๋ฒ•์€ ๊ฒ€์ƒ‰ํ•ด๋ณด์•˜๋‹ค. : / / ์‚ฌ์ด์— ๊ฒ€์ƒ‰ํ•  ๋ฌธ์ž๋ฅผ..

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

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค Lv.0 - n์˜ ๋ฐฐ์ˆ˜ ๐Ÿ’š ๋ฌธ์ œ์„ค๋ช… ์ •์ˆ˜ num๊ณผ n์ด ๋งค๊ฐœ ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ, num์ด n์˜ ๋ฐฐ์ˆ˜์ด๋ฉด 1์„ return n์˜ ๋ฐฐ์ˆ˜๊ฐ€ ์•„๋‹ˆ๋ผ๋ฉด 0์„ returnํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”. ๐Ÿ’š ์ œํ•œ์กฐ๊ฑด 2 ≤ num ≤ 100 2 ≤ n ≤ 9 ๐Ÿ’š ํ’€์ด function solution(num, n) { if(num % n === 0) { return 1 } else { return 0 } } โœ… num์ด n์˜ ๋ฐฐ์ˆ˜์ธ์ง€ ํ™•์ธ๋ถ€ํ„ฐ ํ•ด์•ผํ•œ๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ๊ณ  % ๋Š” ๋‚˜๋จธ์ง€๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” ์—ฐ์‚ฐ์ž๊ณ  (์˜ˆ๋ฅผ ๋“ค์–ด num =18 n=6 ์ผ๋•Œ 18๋กœ 6์„ ๋‚˜๋ˆ„๋ฉด ๋‚˜๋จธ์ง€๊ฐ€ 0์ด ๋‚˜์˜ค๋ฏ€๋กœ 18์€ 6์˜ ๋ฐฐ์ˆ˜์ด๋‹ค.) ๊ทธ๋ž˜์„œ num % n === 0 ํ–ˆ์„๋•Œ ๋‚˜๋จธ์ง€๊ฐ€ 0์ด๋ฉด 1 ์•„๋‹ˆ๋ฉด 0 ์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค.

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค:Javascript] ๋ฐฐ์—ด์˜ ์œ ์‚ฌ๋„

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค Lv.0 - ๋ฐฐ์—ด์˜ ์œ ์‚ฌ๋„ ๐Ÿ’š ๋ฌธ์ œ์„ค๋ช… ๋‘ ๋ฐฐ์—ด์ด ์–ผ๋งˆ๋‚˜ ์œ ์‚ฌํ•œ์ง€ ํ™•์ธํ•ด๋ณด๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ๋ฌธ์ž์—ด ๋ฐฐ์—ด s1๊ณผ s2๊ฐ€ ์ฃผ์–ด์งˆ ๋•Œ ๊ฐ™์€ ์›์†Œ์˜ ๊ฐœ์ˆ˜๋ฅผ returnํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”. ๐Ÿ’š ์ œํ•œ์กฐ๊ฑด 1 ≤ s1, s2์˜ ๊ธธ์ด ≤ 100 1 ≤ s1, s2์˜ ์›์†Œ์˜ ๊ธธ์ด ≤ 10 s1๊ณผ s2์˜ ์›์†Œ๋Š” ์•ŒํŒŒ๋ฒณ ์†Œ๋ฌธ์ž๋กœ๋งŒ ์ด๋ฃจ์–ด์ ธ ์žˆ์Šต๋‹ˆ๋‹ค s1๊ณผ s2๋Š” ๊ฐ๊ฐ ์ค‘๋ณต๋œ ์›์†Œ๋ฅผ ๊ฐ–์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ๐Ÿ’š ํ’€์ด function solution(s1, s2) { const answer = s1.filter(x => s2.includes(x)) return answer.length; } โœ… ๋‘๊ฐœ์˜ ๋ฐฐ์—ด์„ ๋น„๊ตํ•˜๊ณ  ๊ทธ์•ˆ์— ๊ฐ™์€ ๊ฐ’์ด ์žˆ๋Š”์ง€ ํ™•์ธํ›„ ๊ฐœ์ˆ˜๋กœ ๋ฐ˜ํ™˜ํ•ด์•ผ ํ•œ๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ๋‹ค. ๊ฒ€์ƒ‰์œผ๋กœ filter(..

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

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