BlueGit

timfa frameworkv3

Files

frameworkv3 / framework / extensions / extentions.js

extentions.js

format
timfa Tim · pushed by timfa · 4 years ago
24db7846 History
extentions.js 850 B Download Raw
1/**
2 * Extending exising functionality
3 */
4
5Array.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
16Array.prototype.removeAt = function (index) {
17 if (index > -1) {
18 this.splice(index, 1);
19 }
20}
21
22Array.prototype.contains = function (element) {
23 var index = this.indexOf(element);
24
25 return index > -1;
26}
27
28Math.clamp = function (number, min, max) {
29 return Math.min(max, Math.max(min, number));
30}
31
32Math.randomRange = function (min, max) {
33 return min + (Math.random() * (max - min));
34}
35
36Math.lerp = function (a, b, t) {
37 return a + (b - a) * t;
38}
39
40Array.prototype.random = function () {
41 return this[Math.floor((Math.random() * this.length))];
42}