[프로그래머스] 옹알이 (1) & (2)

Chaejung·2023년 9월 13일
0

알고리즘_JavaScript

목록 보기
12/12
post-thumbnail

문제

function solution(babbling) {
    return babbling.filter(ele => {
        const splited = ele.split(/aya|ye|woo|ma/g).filter(e => e)
        const matched = ele.match(/aya|ye|woo|ma/g)
        return !splited.length | matched
    }).length;
}

문제

const ONG_AL = ["aya", "ye", "woo", "ma"];

function isPossibleToPron(str) {
    if (str.length <= 1) return false
    if (ONG_AL.includes(str)) return true
    
    ONG_AL.forEach((basic, idx) => {
        str = str.replaceAll(basic, idx+'')
    })
    for (let i = 0; i < str.length; i++){
        if (i != 0 & str[i-1] === str[i]) return false
        if (isNaN(str[i])) return false
    }
    return true
}

function solution(babbling) {
    var answer = 0;
    babbling.map((ele) => answer += isPossibleToPron(ele) && 1)
    return answer;
}
profile
프론트엔드 기술 학습 및 공유를 활발하게 하기 위해 노력합니다.

0개의 댓글