MCPcopy
hub / github.com/phaserjs/phaser / Range

Function Range

src/utils/array/Range.js:67–129  ·  view source on GitHub ↗
(a, b, options)

Source from the content-addressed store, hash-verified

65 * @return {array} An array of `{ a, b }` pair objects built from the cartesian product of the two input arrays, arranged according to the given options.
66 */
67var Range = function (a, b, options)
68{
69 var max = GetValue(options, 'max', 0);
70 var qty = GetValue(options, 'qty', 1);
71 var random = GetValue(options, 'random', false);
72 var randomB = GetValue(options, 'randomB', false);
73 var repeat = GetValue(options, 'repeat', 0);
74 var yoyo = GetValue(options, 'yoyo', false);
75
76 var out = [];
77
78 if (randomB)
79 {
80 Shuffle(b);
81 }
82
83 // Endless repeat, so limit by max
84 if (repeat === -1)
85 {
86 if (max === 0)
87 {
88 repeat = 0;
89 }
90 else
91 {
92 // Work out how many repeats we need
93 var total = (a.length * b.length) * qty;
94
95 if (yoyo)
96 {
97 total *= 2;
98 }
99
100 repeat = Math.ceil(max / total);
101 }
102 }
103
104 for (var i = 0; i <= repeat; i++)
105 {
106 var chunk = BuildChunk(a, b, qty);
107
108 if (random)
109 {
110 Shuffle(chunk);
111 }
112
113 out = out.concat(chunk);
114
115 if (yoyo)
116 {
117 chunk.reverse();
118
119 out = out.concat(chunk);
120 }
121 }
122
123 if (max)
124 {

Callers 2

Group.jsFile · 0.85
Range.test.jsFile · 0.85

Calls 3

GetValueFunction · 0.85
BuildChunkFunction · 0.85
ShuffleFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…