문제
풀이 (정답 ❌)
function solution(priorities, location) {
let answer = 0;
const array = priorities;
const object = {};
array.forEach((element,index)=>{
object[index] = element;
});
const keys = Object.keys(object);
while(true){
if(array[0]!== Math.max(...array)){
const backToArray = array.shift();
const backToObject = keys.shift();
array.push(backToArray);
keys.push(backToObject);
}
}
answer = keys.indexOf(String(location))+1;
return answer;
}
✏️ 문제 출처
https://programmers.co.kr/learn/courses/30/lessons/42587