๐Ÿ†Ž[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ์˜์–ด๊ฐ€ ์‹ซ์–ด์š”

Chobbyยท2022๋…„ 10์›” 17์ผ
1

Programmers

๋ชฉ๋ก ๋ณด๊ธฐ
121/349

๐Ÿงก๋ฌธ์ œ ์„ค๋ช…

์˜์–ด๊ฐ€ ์‹ซ์€ ๋จธ์“ฑ์ด๋Š” ์˜์–ด๋กœ ํ‘œ๊ธฐ๋˜์–ด์žˆ๋Š” ์ˆซ์ž๋ฅผ ์ˆ˜๋กœ ๋ฐ”๊พธ๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ๋ฌธ์ž์—ด numbers๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ, numbers๋ฅผ ์ •์ˆ˜๋กœ ๋ฐ”๊ฟ” return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด ์ฃผ์„ธ์š”.


๐Ÿ’›์ œํ•œ์‚ฌํ•ญ

  • numbers๋Š” ์†Œ๋ฌธ์ž๋กœ๋งŒ ๊ตฌ์„ฑ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.
  • numbers๋Š” "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" ๋“ค์ด ๊ณต๋ฐฑ ์—†์ด ์กฐํ•ฉ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.
  • 1 โ‰ค numbers์˜ ๊ธธ์ด โ‰ค 50
  • "zero"๋Š” numbers์˜ ๋งจ ์•ž์— ์˜ฌ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.

๐Ÿ’š์ž…์ถœ๋ ฅ ์˜ˆ

numbersresult
"onetwothreefourfivesixseveneightnine"123456789
"onefourzerosixseven"14067

๐Ÿ’™์ž…์ถœ๋ ฅ ์˜ˆ ์„ค๋ช…

์ž…์ถœ๋ ฅ ์˜ˆ #1

  • "onetwothreefourfivesixseveneightnine"๋ฅผ ์ˆซ์ž๋กœ ๋ฐ”๊พผ 123456789๋ฅผ returnํ•ฉ๋‹ˆ๋‹ค.

์ž…์ถœ๋ ฅ ์˜ˆ #2

  • "onefourzerosixseven"๋ฅผ ์ˆซ์ž๋กœ ๋ฐ”๊พผ 14067๋ฅผ returnํ•ฉ๋‹ˆ๋‹ค.

๐Ÿ’œ๋‚˜์˜ ํ’€์ด

function solution(numbers) {
    // num์‚ฌ์ „ ์ƒ์„ฑ
    const num = {
        zero: 0,
        one: 1,
        two: 2,
        three: 3,
        four: 4,
        five: 5,
        six: 6,
        seven: 7,
        eight: 8,
        nine: 9
    }
    // ์‚ฌ์ „์— ๋“ฑ๋ก๋œ ๊ฐ’์„ ๋ถ™์ž„
    return +numbers.match(/one|two|three|four|five|six|seven|eight|nine|zero/g).map(a => num[a]).join("")
    
}
profile
๋‚ด ์ง€์‹์„ ๊ณต์œ ํ•  ์ˆ˜ ์žˆ๋Š” ๋Œ€๋‹ดํ•จ

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