/*
https://school.programmers.co.kr/learn/courses/30/lessons/81301

๋ฌธ์ œ ์„ค๋ช…
๋„ค์˜ค์™€ ํ”„๋กœ๋„๊ฐ€ ์ˆซ์ž๋†€์ด๋ฅผ ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ๋„ค์˜ค๊ฐ€ ํ”„๋กœ๋„์—๊ฒŒ ์ˆซ์ž๋ฅผ ๊ฑด๋„ฌ ๋•Œ ์ผ๋ถ€ ์ž๋ฆฟ์ˆ˜๋ฅผ ์˜๋‹จ์–ด๋กœ ๋ฐ”๊พผ ์นด๋“œ๋ฅผ ๊ฑด๋„ค์ฃผ๋ฉด ํ”„๋กœ๋„๋Š” ์›๋ž˜ ์ˆซ์ž๋ฅผ ์ฐพ๋Š” ๊ฒŒ์ž„์ž…๋‹ˆ๋‹ค.

๋‹ค์Œ์€ ์ˆซ์ž์˜ ์ผ๋ถ€ ์ž๋ฆฟ์ˆ˜๋ฅผ ์˜๋‹จ์–ด๋กœ ๋ฐ”๊พธ๋Š” ์˜ˆ์‹œ์ž…๋‹ˆ๋‹ค.

1478 → "one4seveneight"
234567 → "23four5six7"
10203 → "1zerotwozero3"
์ด๋ ‡๊ฒŒ ์ˆซ์ž์˜ ์ผ๋ถ€ ์ž๋ฆฟ์ˆ˜๊ฐ€ ์˜๋‹จ์–ด๋กœ ๋ฐ”๋€Œ์–ด์กŒ๊ฑฐ๋‚˜, ํ˜น์€ ๋ฐ”๋€Œ์ง€ ์•Š๊ณ  ๊ทธ๋Œ€๋กœ์ธ ๋ฌธ์ž์—ด s๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค. s๊ฐ€ ์˜๋ฏธํ•˜๋Š” ์›๋ž˜ ์ˆซ์ž๋ฅผ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”.

์ฐธ๊ณ ๋กœ ๊ฐ ์ˆซ์ž์— ๋Œ€์‘๋˜๋Š” ์˜๋‹จ์–ด๋Š” ๋‹ค์Œ ํ‘œ์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.

์ˆซ์ž	์˜๋‹จ์–ด
0	zero
1	one
2	two
3	three
4	four
5	five
6	six
7	seven
8	eight
9	nine
์ œํ•œ์‚ฌํ•ญ
1 ≤ s์˜ ๊ธธ์ด ≤ 50
s๊ฐ€ "zero" ๋˜๋Š” "0"์œผ๋กœ ์‹œ์ž‘ํ•˜๋Š” ๊ฒฝ์šฐ๋Š” ์ฃผ์–ด์ง€์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
return ๊ฐ’์ด 1 ์ด์ƒ 2,000,000,000 ์ดํ•˜์˜ ์ •์ˆ˜๊ฐ€ ๋˜๋Š” ์˜ฌ๋ฐ”๋ฅธ ์ž…๋ ฅ๋งŒ s๋กœ ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค.

์ œํ•œ์‹œ๊ฐ„ ์•ˆ๋‚ด
์ •ํ™•์„ฑ ํ…Œ์ŠคํŠธ : 10์ดˆ
*/

const solution = (str) => {
  // ์ธ์ž ๊ฐ’๊ณผ ๋น„๊ตํ•  ๋ฐฐ์—ด ์ƒ์„ฑ
  const words = [
    'zero',
    'one',
    'two',
    'three',
    'four',
    'five',
    'six',
    'seven',
    'eight',
    'nine',
  ];

  let answer = str;

  // ์• ์ดˆ์— ์ƒ๊ฐํ–ˆ๋˜๊ฑด ๋Œ€์ฒดํ•  ๋ฐฐ์—ด์€ ์„ ์–ธํ•ด๋†จ์œผ๋‹ˆ, ์ธ์ž ๊ฐ’์„ ์„ ์–ธํ•œ ๋ฐฐ์—ด ๊ฐ’์˜ ๋‹จ์–ด๋“ค๋กœ ์ชผ๊ฐค๋ ค๊ณ  ํ–ˆ๋‹ค. ๊ทธ๋ž˜์•ผ ์ˆซ์ž๋กœ ๋ณ€ํ™˜์ด ๋˜๋‹ˆ๊น
  // split๊นŒ์ง€๋Š” ์ƒ๊ฐํ•ด๋ดค๋Š”๋ฐ ์ดํ›„ ๊ณผ์ •์—์„œ ์• ๋ฅผ ๋จน์—ˆ๋‹ค. ์–ด์ฐจํ”ผ words์˜ length๋งŒํผ ๋Œ์œผ๋‹ˆ ํ•ญ์ƒ ์ธ๋ฑ์Šค ๊ฐ’๊ณผ ํ•ด๋‹น ๋ฐฐ์—ด์˜ ๊ฐ’์ด ์ผ์น˜ํ•œ๋‹ค.
  // ์˜ˆ๋ฅผ๋“ค์–ด, zero๋Š” ์ธ๋ฑ์Šค ๊ฐ’์ด 0, one์€ ์ธ๋ฑ์Šค ๊ฐ’์ด 1 ... ์ด๋ ‡๊ฒŒ ์ญ‰ ์ธ๋ฑ์Šค ๊ฐ’์ด ์ผ์น˜ํ•˜๋‹ˆ, ์ด ์ธ๋ฑ์Šค ๊ฐ’์„ ์“ฐ๋Š”๊ฑฐ ๊นŒ์ง€๋Š” ์ƒ๊ฐํ•ด๋ƒˆ๋Š”๋ฐ ์ด ์ดํ›„ ๊ณผ์ •์—์„œ ์• ๋ฅผ ๋จน์—ˆ๋‹ค.
  // ๊ฒฐ๊ตญ ๊ตฌ๊ธ€๋ง์œผ๋กœ join ๋ฉ”์„œ๋“œ๋กœ ํ•ด๊ฒฐํ•œ๊ฑธ ์ฐพ์•„๋ดค๋‹ค....
  for (let i = 0; i < words.length; i++) {
    let arr = answer.split(words[i]);
    // console.log(arr);
    answer = arr.join(i);
    // console.log('hi', answer); <- ๋กœ๊ทธ ์ฐํžˆ๋Š”๊ฑฐ ์‰ฝ๊ฒŒ ๋ณด๋ ค๊ณ  'hi' ๋ฌธ์ž์—ด ์ถ”๊ฐ€
  }
  return Number(answer);
};

console.log(solution('one4seveneight'));
console.log(solution('23four5six7'));
console.log(solution('2three45sixseven'));
console.log(solution('123'));

์•„์‰ฌ์›€์ด ๋งŽ์ด ๋‚จ๋Š” ๋ฌธ์ œ.. join ๋ฉ”์„œ๋“œ๋กœ ์ธ๋ฑ์Šค ๊ฐ’์„ ์“ฐ๋Š”๊ฑธ ์™œ ์ƒ๊ฐ์„ ๋ชปํ–ˆ์„๊นŒ..

์•„์‰ฝ์ง€๋งŒ ๋ชป ํ‘ผ๊ฑด ๋ชป ํ‘ผ๊ฑฐ๋‹ค.

๋ณต์‚ฌํ–ˆ์Šต๋‹ˆ๋‹ค!