๐ŸŸฃ ์˜ค๋Š˜์˜ ๋ฌธ์ œ ํšŒ๊ณ 

๊น€ํƒœ์šฑยท2023๋…„ 4์›” 14์ผ
0
post-thumbnail

๐Ÿ˜ญ ์˜ค๋Š˜์˜ ๋ฌธ์ œ ํ•ฅ์ง #1

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

๋ฌธ์ œ ์„ค๋ช…
์˜์–ด์—์„  a, e, i, o, u ๋‹ค์„ฏ ๊ฐ€์ง€ ์•ŒํŒŒ๋ฒณ์„ ๋ชจ์Œ์œผ๋กœ ๋ถ„๋ฅ˜ํ•ฉ๋‹ˆ๋‹ค. ๋ฌธ์ž์—ด my_string์ด ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ ๋ชจ์Œ์„ ์ œ๊ฑฐํ•œ ๋ฌธ์ž์—ด์„ returnํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”.

์ œํ•œ์‚ฌํ•ญ

  • my_string์€ ์†Œ๋ฌธ์ž์™€ ๊ณต๋ฐฑ์œผ๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ์Šต๋‹ˆ๋‹ค.
  • 1 โ‰ค my_string์˜ ๊ธธ์ด โ‰ค 1,000

์ž…์ถœ๋ ฅ ์˜ˆ

my_stringresult
"bus""bs"
"nice to meet you""nc t mt y"

๋‚˜์˜ ํ’€์ด

function solution(my_string) {
  let vowel = ["a", "e", "i", "o", "u"];
  var answer = my_string.split("").filter((e) => !vowel.includes(e));
  return answer.join("");
}

๊ตฌํ˜„ ์ ‘๊ทผ
1. ํ•ด๋‹น ๋ชจ์Œ์ด ์กด์žฌํ•˜๋Š”์ง€ ํŒ๋‹จํ•˜๊ธฐ ์œ„ํ•œ ๋ฉ”์†Œ๋“œ ์‚ฌ์šฉ์ด ํ•„์š”ํ•  ๊ฑฐ ๊ฐ™์•„ ๋ฌธ์ž์—ด ์ž…๋ ฅ ๊ฐ’์„ ๋ฐฐ์—ด๋กœ ๋ฐ˜ํ™˜
2. filter๋ฅผ ํ†ตํ•ด ํ˜„์žฌ ๊ฐ’ e์— vowel๊ฐ’์ด ํฌํ•จ๋˜์–ด์žˆ๋Š”์ง€,
NOT ๋…ผ๋ฆฌ์—ฐ์‚ฐ์ž (!)๋ฅผ ํ†ตํ•ด ๋ชจ์Œ์ด ํฌํ•จ๋˜์–ด ์žˆ์ง€ ์•Š์€ ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•˜๋Š” ํ•จ์ˆ˜ ๊ตฌํ˜„
3. join ๋ฉ”์†Œ๋“œ๋ฅผ ํ†ตํ•ด์„œ ๋ฐ˜ํ™˜๋œ ๋ฌธ์ž์—ด ๋ฐฐ์—ด์„ ๋ฌธ์ž์—ด๋กœ ๋ณ‘ํ•ฉ

๋ฌธ์ œ์ 
1. ๋ฌธ์ œ๋ฅผ ํ’€ ๋•Œ ๊ณ„์†ํ•ด์„œ ์ฐธ๊ณ ๋งŒ ํ•˜๊ณ  ์Šค์Šค๋กœ ํ’€ ๋…ธ๋ ฅ์„ ํ•˜์ง€ ์•Š์•„์„œ ๋ฌธ์ œ๋ฅผ ํ‘ธ๋Š” ์‚ฌ๊ณ ๊ฐ€ ๋Š˜์ง€ ์•Š๋Š” ๊ฒƒ์„ ์Šค์Šค๋กœ ๊นจ๋‹ฌ์Œ

  1. ๋‹ค์‹œ LV0 ๋ถ€ํ„ฐ ์ฝ”ํ…Œ๊นŒ์ง€ ๋˜๋Š”๋ฐ๋กœ ๋ฌธ์ œ๋ฅผ ํ’€๋„๋ก ๋…ธ๋ ฅํ•  ๊ฒƒ.

๐Ÿ˜ญ ์˜ค๋Š˜์˜ ๋ฌธ์ œ ํ•ฅ์ง #2

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

๋ฌธ์ œ ์„ค๋ช…
๋‘ ๋ฐฐ์—ด์ด ์–ผ๋งˆ๋‚˜ ์œ ์‚ฌํ•œ์ง€ ํ™•์ธํ•ด๋ณด๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ๋ฌธ์ž์—ด ๋ฐฐ์—ด s1๊ณผ s2๊ฐ€ ์ฃผ์–ด์งˆ ๋•Œ ๊ฐ™์€ ์›์†Œ์˜ ๊ฐœ์ˆ˜๋ฅผ returnํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”.

์ œํ•œ์‚ฌํ•ญ

  • 1 โ‰ค s1, s2์˜ ๊ธธ์ด โ‰ค 100
  • 1 โ‰ค s1, s2์˜ ์›์†Œ์˜ ๊ธธ์ด โ‰ค 10
  • s1๊ณผ s2์˜ ์›์†Œ๋Š” ์•ŒํŒŒ๋ฒณ ์†Œ๋ฌธ์ž๋กœ๋งŒ ์ด๋ฃจ์–ด์ ธ ์žˆ์Šต๋‹ˆ๋‹ค
  • s1๊ณผ s2๋Š” ๊ฐ๊ฐ ์ค‘๋ณต๋œ ์›์†Œ๋ฅผ ๊ฐ–์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

์ž…์ถœ๋ ฅ ์˜ˆ

s1s2result
["a", "b", "c"]["com", "b", "d", "p", "c"]2
["n", "omg"]["m", "dot"]0

๋‚˜์˜ ํ’€์ด

function solution(s1, s2) {
  var answer = s1.filter((e) => s2.includes(e)).length;
  return answer;
}

๊ตฌํ˜„ ์ ‘๊ทผ
1. ํ•ด๋‹น ๋ฌธ์ œ ์—ญ์‹œ ์œ„ ๋ฌธ์ œ์™€ ๊ฐ™์€ ํ˜•์‹์˜ ๊ตฌํ˜„์ด์—ˆ๊ธฐ์— ๊ทธ๋Œ€๋กœ ํ’€ ์ˆ˜ ์žˆ์—ˆ๋‹ค.


๐Ÿ˜ญ ์˜ค๋Š˜์˜ ๋ฌธ์ œ ํ•ฅ์ง #3

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

๋ฌธ์ œ ์„ค๋ช…
๋ฌธ์ž์—ด my_string์ด ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค. my_string์•ˆ์˜ ๋ชจ๋“  ์ž์—ฐ์ˆ˜๋“ค์˜ ํ•ฉ์„ returnํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”.

์ œํ•œ์‚ฌํ•ญ

  • 1 โ‰ค my_string์˜ ๊ธธ์ด โ‰ค 1,000
  • my_string์€ ์†Œ๋ฌธ์ž, ๋Œ€๋ฌธ์ž ๊ทธ๋ฆฌ๊ณ  ํ•œ์ž๋ฆฌ ์ž์—ฐ์ˆ˜๋กœ๋งŒ ๊ตฌ์„ฑ๋˜์–ด์žˆ์Šต๋‹ˆ๋‹ค.

์ž…์ถœ๋ ฅ ์˜ˆ

my_stringresult
"aAb1B2cC34oOp"10
"1a2b3c4d123"16

๋‚˜์˜ ํ’€์ด

function solution(my_string) {
  var answer = my_string
    .split("")
    .filter((e) => !isNaN(e))
    .reduce((a, c) => a + parseInt(c), 0);
  return answer;
}

๊ตฌํ˜„ ์ ‘๊ทผ
1.๊ตฌ๋ณ„ ์—†์ด ์„ž์—ฌ์žˆ๋Š” ๋ฐฐ์—ด์„ ํ•˜๋‚˜์”ฉ ๋‚˜๋ˆ„๊ธฐ ์œ„ํ•ด split ๋ฉ”์†Œ๋“œ ์‚ฌ์šฉ.
2. filter๋ฅผ ํ†ตํ•ด ๋ฌธ์ž์—ด ์—˜๋ฆฌ๋จผํŠธ ๋“ค์„ ๊ฐ๊ฐ ํ˜•๋ณ€ํ™˜ ์‹œ NaN์ด ๋˜์ง€ ์•Š๋Š” ๊ฐ’ ๋ฐ˜ํ™˜.
3. reduce๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ˜„์žฌ(c) ๊ฐ’์„ ํ˜•๋ณ€ํ™˜ ์‹œ์ผœ์ค€ ๋’ค ์ดˆ๊ธฐ ๊ฐ’์„ 0์œผ๋กœ ์„ค์ •ํ•˜์—ฌ ๋ˆ„์‚ฐ.

profile
๋ฐฉ๋ฒ•์„ ์—ฐ๊ตฌํ•  ์ค„ ์•„๋Š” ๊ฐœ๋ฐœ์ž!

0๊ฐœ์˜ ๋Œ“๊ธ€