
function solution(priorities, location) {
var answer = 0
let ranking = 0
while (priorities.length !== 0) {
if (Math.max(...priorities) > priorities[0]) {
if (--location < 0) location = priorities.length - 1
priorities.push(priorities.shift())
} else {
ranking++
if (--location < 0) return ranking
priorities.shift()
}
}
console.log("answer: ", ranking)
answer = ranking
return answer
}
코드 2
function solution(priorities, location) {
var list = priorities.map((t, i) => ({
my: i === location,
val: t,
}))
var count = 0
while (true) {
var cur = list.shift()
if (list.some((t) => t.val > cur.val)) {
list.push(cur)
} else {
count++
if (cur.my) return count
}
}
}