문제
풀이 1
function solution(N, stages) {
let failResult = []
for (let n=1; n<=N;n++){
let completePeople =0
let failPeople = 0
for (let i=0; i<stages.length; i++){
if (n < stages[i]) completePeople++
else if(n === stages[i]) failPeople++
}
failResult.push([n ,failPeople / (completePeople + failPeople)])
}
return failResult.sort((a,b) => b[1]-a[1]).map(v => v[0])
}
풀이 2
function solution(N, stages) {
let result = [];
for(let i=1; i<=N; i++){
let reach = stages.filter((x) => x >= i).length;
let curr = stages.filter((x) => x === i).length;
result.push([i, curr/reach]);
}
result.sort((a,b) => b[1] - a[1]);
return result.map((x) => x[0]);
}