느려도 한걸음씩

문제 13 - 실패율 본문

알고리즘/코테대비 100문제

문제 13 - 실패율

hoj0806 2025. 2. 14. 00:37

문제 링크 : https://school.programmers.co.kr/learn/courses/30/lessons/42889

 

프로그래머스

SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프

programmers.co.kr

 

문제

 

내 정답 코드

function solution(N, stages) {
    let answer = []
    let failedRatio = []
    for(let i = 1; i <= N; i++) {
        let arr = stages.filter(stage => stage >= i)
       let staged = arr.length
       let notClear = stages.filter(stage => stage === i).length
       if(staged === 0) {
           failedRatio.push(0)
       } else {
             failedRatio.push(notClear / staged)
       }
      
    }
    let sortRatio = [...failedRatio].sort((a, b) => b- a)
    
   
    for(let i = 0; i < failedRatio.length; i++) {
       answer.push(failedRatio.indexOf(sortRatio[i]) + 1)
        failedRatio[failedRatio.indexOf(sortRatio[i])] = 'checked'
        
    }
    return answer
}