function solution(priorities, location) {
var answer = 0;
let count = 0;
while(priorities.length > 0){
//1. 인쇄 대기목록의 가장 앞에 있는 문서(J)를 대기목록에서 꺼냅니다.
let j = priorities.shift();
//2. 나머지 인쇄 대기목록에서 J보다 중요도가 높은 문서가 한 개라도 존재하면 J를 대기목록의 가장 마지막에 넣습니다.
if(priorities.some((prior) => {return prior > j;})) {
priorities.push(j);
//3. 그렇지 않으면 J를 인쇄합니다.
} else {
count++;
if(location == 0) {
answer = count;
return answer;
}
}
//변경되는 location 트래킹
if(location == 0) {
location = priorities.length - 1;
} else {
location -= 1;
}
}
}