λ€μ€μ νλ‘λκ° μ«μλμ΄λ₯Ό νκ³ μμ΅λλ€. λ€μ€κ° νλ‘λμκ² μ«μλ₯Ό κ±΄λ¬ λ μΌλΆ μλ¦Ώμλ₯Ό μλ¨μ΄λ‘ λ°κΎΌ μΉ΄λλ₯Ό 건λ€μ£Όλ©΄ νλ‘λλ μλ μ«μλ₯Ό μ°Ύλ κ²μμ λλ€.
λ€μμ μ«μμ μΌλΆ μλ¦Ώμλ₯Ό μλ¨μ΄λ‘ λ°κΎΈλ μμμ λλ€.
μ΄λ κ² μ«μμ μΌλΆ μλ¦Ώμκ° μλ¨μ΄λ‘ λ°λμ΄μ‘κ±°λ, νΉμ λ°λμ§ μκ³ κ·Έλλ‘μΈ λ¬Έμμ΄ s
κ° λ§€κ°λ³μλ‘ μ£Όμ΄μ§λλ€.
sκ° μλ―Ένλ μλ μ«μλ₯Ό return νλλ‘ solution ν¨μλ₯Ό μμ±ν΄μ£ΌμΈμ.
μ°Έκ³ λ‘ κ° μ«μμ λμλλ μλ¨μ΄λ λ€μ νμ κ°μ΅λλ€.
https://school.programmers.co.kr/learn/courses/30/lessons/81301
function solution(s) {
let answer = s;
answer = answer.replace(/zero/gi, "0");
answer = answer.replace(/one/gi, "1");
answer = answer.replace(/two/gi, "2");
answer = answer.replace(/three/gi, "3");
answer = answer.replace(/four/gi, "4");
answer = answer.replace(/five/gi, "5");
answer = answer.replace(/six/gi, "6");
answer = answer.replace(/seven/gi, "7");
answer = answer.replace(/eight/gi, "8");
answer = answer.replace(/nine/gi, "9");
return Number(answer);
}
function solution(s) {
let numbers = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"];
var answer = s;
for(let i=0; i< numbers.length; i++) {
let arr = answer.split(numbers[i]);
answer = arr.join(i);
}
return Number(answer);
}
str.split(separator, [limit])
str.join(separator)
"javascript".split("j"); // ["", "avascript"]
"javascript".split("j").join(1); // 1avascript
// λ°°μ΄ λ΄ μμκ° νλμΌ κ²½μ° μ°κ²°μ μμ΄ λ¬Έμμ΄μ΄ λ°ν μμ
"javascript".split("g"); // ["javascript"]
"javascript".split("g").join(1); // // javascript