Skip to content

Commit d187a4c

Browse files
committed
Process / 심화
1 parent 94221e5 commit d187a4c

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

bona1122/[week3]Queue/Process.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// https://school.programmers.co.kr/learn/courses/30/lessons/42587
2+
3+
function solution(priorities, location) {
4+
const queue = priorities.map((item, idx) => [item, idx]);
5+
let poppedNum = 0;
6+
7+
while (queue.length > 0) {
8+
const current = queue.shift();
9+
const isHighestPriority = queue.every((item) => item[0] <= current[0]);
10+
11+
if (isHighestPriority) {
12+
poppedNum++;
13+
if (current[1] === location) return poppedNum;
14+
} else {
15+
queue.push(current);
16+
}
17+
}
18+
}

0 commit comments

Comments
 (0)