Skip to content

Commit df8ffd4

Browse files
committed
process / �ы�
1 parent 0d2f982 commit df8ffd4

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

JustDevRae/Queue/process.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
function solution(priorities, location) {
2+
var answer = 0;
3+
const queue = priorities.map((priority, index) => ({ priority, index }));
4+
5+
while (queue.length > 0) {
6+
const current = queue.shift();
7+
8+
const highPriority = queue.some((item) => item.priority > current.priority);
9+
10+
if (highPriority) {
11+
queue.push(current);
12+
} else {
13+
answer++;
14+
15+
if (current.index === location) {
16+
return answer;
17+
}
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)