1
+ // Used to generate all possible combinations of criteria for matching
2
+ /*
3
+ Order matters:
4
+ Example:
5
+ - First criteria is the difficulty
6
+ - Second criteria is the language
7
+ - Combinations are [easy, python], ... , [hard, cplusplus]
8
+ - Queue names are easy.python, ... , hard.cplusplus
9
+ If you switch the order of the criteria, the combinations will be reversed!
10
+ Example:
11
+ - Combinations become [python, easy], ... , [cplusplus, hard]
12
+ - Queue names become python.easy, ... , cplusplus.hard
13
+
14
+ Functions can be used with other criteria like difficulty, topic, etc.
15
+ These functions can be chained multiple times to generate routing criteria longer than 2
16
+ */
17
+
18
+ function generateCombinations ( criteria1 , criteria2 ) {
19
+ const combinations = [ ] ;
20
+ for ( let i = 0 ; i < criteria1 . length ; i ++ ) {
21
+ for ( let j = 0 ; j < criteria2 . length ; j ++ ) {
22
+ combinations . push ( [ criteria1 [ i ] , criteria2 [ j ] ] ) ;
23
+ }
24
+ }
25
+ return combinations ;
26
+ }
27
+
28
+ // output string is based on order of fields in the combinations array
29
+ function generateQueueNames ( combinations ) {
30
+ const queueNames = [ ] ;
31
+ for ( const combination of combinations ) {
32
+ const queueName = `${ combination [ 0 ] } .${ combination [ 1 ] } ` ;
33
+ queueNames . push ( queueName ) ;
34
+ }
35
+ return queueNames ;
36
+ }
37
+
38
+ module . exports = { generateCombinations, generateQueueNames } ;
0 commit comments