function solution(N, stages) {
var answer = [];
var failed = new Array(N)
var user = stages.length
for(var index =0; index < failed.length; index++){
failed[index] = 0
var c = 0,failedCount = 0
for(var indexStages = 0; indexStages < stages.length; indexStages++ ){
if(index+1 === stages[indexStages]){
failedCount += 1
c += 1
}
}
if(failedCount === 0){
failed[index] = 0
} else{
failed[index] = failedCount/user
var user = user - c
}
}
var count = 0
var visited = new Array(N).fill(0)
while (count < N){
count++
var maxVal = -1
var maxIn = 0
for(var i = 0; i < N; i++){
if(maxVal < failed[i] && visited[i] === 0){
maxVal = failed[i]
maxIn = i
}
}
visited[maxIn] = 1
answer.push(maxIn+1)
}
console.log(answer)
return answer;
}