BlueGit

timfa frameworkv3

Files

frameworkv3 / framework / extensions / extentions.js

extentions.js

particles
timfa Tim · pushed by timfa · 4 years ago
0665883f History
extentions.js 855 B Download Raw
1/**
2 * Extending exising functionality
3 */
4
5Array.prototype.remove = function(element)
6{
7 var index = this.indexOf(element);
8
9 if (index > -1)
10 {
11 this.splice(index, 1);
12 }
13 else
14 {
15 console.error("Element not part of array!", this, element);
16 }
17}
18
19Array.prototype.removeAt = function(index)
20{
21 if (index > -1)
22 {
23 this.splice(index, 1);
24 }
25}
26
27Array.prototype.contains = function(element)
28{
29 var index = this.indexOf(element);
30
31 return index > -1;
32}
33
34Math.clamp = function(number, min, max)
35{
36 return Math.min(max, Math.max(min, number));
37}
38
39Math.randomRange = function(min, max)
40{
41 return min + (Math.random() * (max - min));
42}
43
44Math.lerp = function(a, b, t)
45{
46 return a + (b - a) * t;
47}
48
49Array.prototype.random = function ()
50{
51 return this[Math.floor((Math.random()*this.length))];
52}