-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjcl.utilities.js
52 lines (34 loc) · 1.16 KB
/
jcl.utilities.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
JCL.utilities = {
// randomInt()
// Returns an integer between the specified minimum (inclusive) and maximum (exclusive).
randomInt: function(min, max) {
if (min !== undefined && max !== undefined) {
return Math.floor((max - min) * Math.random()) + min;
} else { throw new Error("utilities.randomInt() Error: Missing min or max argument."); }
},
// radians()
// Converts degrees into radians.
radians: function(degrees) {
return (Math.PI / 180) * degrees;
},
// degrees()
// Converts radians into degrees.
degrees: function(radians) {
return radians * (180 / Math.PI);
},
// bounds()
// Returns the minimum and maximum value for a given collection.
bounds: function(collection) {
var i, j, min, max;
for (i=0, j=collection.length; i<j; i++) {
if (!min) { min = collection[i]; }
if (!max) { max = collection[i]; }
if (collection[i] > max) { max = collection[i]; }
if (collection[i] < min) { min = collection[i]; }
}
return {
min: min,
max: max
}
}
};