vowels

problem

주어진 λ¬Έμžμ—΄μ— μžˆλŠ” λͺ¨μŒμ˜ 개수λ₯Ό λ°˜ν™˜ν•˜κΈ°. λͺ¨μŒμ€ a, e, i, o, u

solution

function vowels (str) {
    const matches = str.match(/[aeiou]/gi);
    return matches ? matches.length : 0;
}
function vowels (str) {
    const checker = ['a', 'e', 'i', 'o', 'u'];
    let count = 0;

    for(let char of checker.toLowerCase()) {
        if(checker.includes(char)) {
            count++;
        }
    }

    return count;
}

description

  • μ •κ·œν‘œν˜„μ‹μ„ μ‚¬μš©ν•˜μ—¬ λͺ¨μŒμ„ μ°Ύμ•„λ‚΄μ–΄ λ°°μ—΄λ‘œ λ°˜ν™˜ν•œλ‹€. μ •κ·œμ‹ ν‘œν˜„μ„ μ•Œμ•„λ‘λ©΄ 쒋을 λ“―.

  • λ°˜λ³΅λ¬Έμ„ μ‚¬μš©ν•˜μ—¬ λͺ¨μŒμ„ μ°Ύμ•„λ‚΄μ–΄ countλ₯Ό μ¦κ°€μ‹œν‚¨λ‹€.

Last updated