function solution(priorities, location) {
const dimen_arr = priorities.map((v, i) => [i, v])
const stack = []
while(true){
let first = dimen_arr.shift()
if(dimen_arr.some(v => first[1] < v[1])){
dimen_arr.push(first)
} else {
stack.push(first[0])
}
if(dimen_arr.length === 0) break;
}
return stack.indexOf(location) + 1
}