Skip to content

Commit 421ec9c

Browse files
committed
프로세스(심화)
1 parent b5046ab commit 421ec9c

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

unn04012/queue/process.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
function solution(priorities, location) {
2+
let answer = 1;
3+
const queue = [];
4+
5+
const prioritiesWithIndex = priorities.map((priority, index) => ({ priority, index }));
6+
7+
while (prioritiesWithIndex.length) {
8+
const { priority, index } = prioritiesWithIndex.shift();
9+
10+
const checkPriority = prioritiesWithIndex.findIndex((e) => e.priority > priority);
11+
12+
// 우선순위가 더 큰 프로세스가 없으면
13+
if (checkPriority === -1) {
14+
if (location === index) return queue.length + 1;
15+
queue.push(priority);
16+
continue;
17+
}
18+
19+
prioritiesWithIndex.push({ priority, index });
20+
}
21+
22+
return answer;
23+
}
24+
console.log(solution([1, 1, 9, 1, 1, 1], 0));

0 commit comments

Comments
 (0)