We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0d2f982 commit df8ffd4Copy full SHA for df8ffd4
JustDevRae/Queue/process.js
@@ -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