9
9
var assignTasks = function ( servers , tasks ) {
10
10
11
11
const toBeCompleted = new MinPriorityQueue ( {
12
- compare : ( a , b ) => {
13
- if ( a [ 0 ] === b [ 0 ] ) return a [ 1 ] - b [ 1 ] ;
12
+ compare : ( a , b ) => {
13
+ if ( a [ 0 ] === b [ 0 ] ) return a [ 1 ] - b [ 1 ] ;
14
14
return a [ 0 ] - b [ 0 ] ;
15
15
}
16
16
} ) ;
17
17
18
18
const freeServers = new MinPriorityQueue ( {
19
- compare : ( a , b ) => {
20
- if ( a [ 0 ] === b [ 0 ] ) return a [ 1 ] - b [ 1 ] ;
19
+ compare : ( a , b ) => {
20
+ if ( a [ 0 ] === b [ 0 ] ) return a [ 1 ] - b [ 1 ] ;
21
21
return a [ 0 ] - b [ 0 ] ;
22
22
}
23
23
} ) ;
24
24
25
- for ( let i = 0 ; i < servers . length ; i ++ ) {
25
+ for ( let i = 0 ; i < servers . length ; i ++ ) {
26
26
const weight = servers [ i ] ;
27
27
const idx = i ;
28
28
freeServers . enqueue ( [ weight , idx ] ) ;
@@ -31,17 +31,16 @@ var assignTasks = function(servers, tasks) {
31
31
let sec = 0 ;
32
32
const result = [ ] ;
33
33
34
- for ( let i = 0 ; i < tasks . length ; i ++ ) {
34
+ for ( let i = 0 ; i < tasks . length ; i ++ ) {
35
35
sec = Math . max ( i , sec ) ;
36
36
37
37
// if the we don't have server available then jump to the next imidiate
38
38
// time when the server will be available.
39
- if ( freeServers . isEmpty ( ) ) {
39
+ if ( freeServers . isEmpty ( ) ) {
40
40
sec = toBeCompleted . front ( ) [ 0 ] ;
41
41
}
42
- while ( ! toBeCompleted . isEmpty ( ) &&
43
- toBeCompleted . front ( ) [ 0 ] <= sec
44
- ) {
42
+ while ( ! toBeCompleted . isEmpty ( ) &&
43
+ toBeCompleted . front ( ) [ 0 ] <= sec ) {
45
44
const [ endTime , serverIdx ] = toBeCompleted . dequeue ( ) ;
46
45
const weight = servers [ serverIdx ] ;
47
46
freeServers . enqueue ( [ weight , serverIdx ] ) ;
0 commit comments