let's get IT with DAVINA ๐Ÿ’ป

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

DEV_IN/๋ฌธ์ œํ’€์ด

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

๋‹ค๋นˆ์น˜์ฝ”๋“œ๐Ÿ’Ž 2023. 3. 17. 16:41

โ“๋ฌธ์ œ ์„ค๋ช…

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

๐Ÿšซ ์ œํ•œ์‚ฌํ•ญ

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

โ—๏ธ๋น„๋‹ˆ's ํ’€์ด

๋ฌธ์ž์—ด์—์„œ ๋ชจ์Œ๋งŒ ์ œ๊ฑฐํ•˜๋ฉด ๋˜๋‹ˆ replace๋ฉ”์„œ๋“œ๋ฅผ ์จ์•ผ๊ฒ ๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ๋‹ค.

ํ•˜์ง€๋งŒ ์ •๊ทœํ‘œํ˜„์‹์„ ๋‹ค๋ฃจ๋Š”๋ฐ ์–ด๋ ค์›Œ์„œ ์‹œ๊ฐ„์„ ๋งŽ์ด ์žก์•„๋จน์—ˆ๋‹ค..

function solution(my_string) {
    let reg=/[aeiou]/g
    return my_string.replaceAll(reg,"")
}

⊕ Extra Knowledge ++

  • string.prototype.replaceAll()
    • replaceAll()์€ patter์˜ ๋ชจ๋“  ์ผ์น˜ ํ•ญ๋ชฉ์ด replacement๋กœ ๋Œ€์ฒด๋œ ์ƒˆ ๋ฌธ์ž์—ด์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
    • ๊ตฌ๋ฌธ ๐Ÿ”ฝ
replaceAll(pattern, replacement)
  • ์ •๊ทœํ‘œํ˜„์‹
    • //๋กœ ๊ฐ์‹ธ์ฃผ๊ธฐ
    • []๋Š” ๋ฒ”์œ„ (๋ชจ์Œaeiou์ค‘์— ํ•˜๋‚˜)
    • replaceAll() method๋Š” global RegExp argument์™€ ์“ฐ์—ฌ์•ผํ•œ๋‹ค๊ณ  ์—๋Ÿฌ๊ฐ€ ๋œจ๋‹ˆ g๋ฅผ ์ถ”๊ฐ€ํ•ด์„œ global๋กœ ๋งŒ๋“ค์–ด์ฃผ์ž
const reg = /[aeiou]/g
Comments