BlueGit

timfa frameworkv3

Files

frameworkv3 / framework / extentions.js

extentions.js

add array.random
timfa Tim Falken · pushed by timfa · 7 years ago
1a960e0e History
extentions.js 589 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.contains = function(element)
20{
21 var index = this.indexOf(element);
22
23 return index > -1;
24}
25
26Math.clamp = function(number, min, max)
27{
28 return Math.min(max, Math.max(min, number));
29}
30
31Array.prototype.random = function ()
32{
33 return this[Math.floor((Math.random()*this.length))];
34}