| 1 | /** |
| 2 | * Extending exising functionality |
| 3 | */ |
| 4 | |
| 5 | Array.prototype.remove = function (element) { |
| 6 | var index = this.indexOf(element); |
| 7 | |
| 8 | if (index > -1) { |
| 9 | this.splice(index, 1); |
| 10 | } |
| 11 | else { |
| 12 | console.error("Element not part of array!", this, element); |
| 13 | } |
| 14 | } |
| 15 | |
| 16 | Array.prototype.removeAt = function (index) { |
| 17 | if (index > -1) { |
| 18 | this.splice(index, 1); |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | Array.prototype.contains = function (element) { |
| 23 | var index = this.indexOf(element); |
| 24 | |
| 25 | return index > -1; |
| 26 | } |
| 27 | |
| 28 | Math.clamp = function (number, min, max) { |
| 29 | return Math.min(max, Math.max(min, number)); |
| 30 | } |
| 31 | |
| 32 | Math.randomRange = function (min, max) { |
| 33 | return min + (Math.random() * (max - min)); |
| 34 | } |
| 35 | |
| 36 | Math.lerp = function (a, b, t) { |
| 37 | return a + (b - a) * t; |
| 38 | } |
| 39 | |
| 40 | Array.prototype.random = function () { |
| 41 | return this[Math.floor((Math.random() * this.length))]; |
| 42 | } |