/** * Extending exising functionality */ Array.prototype.remove = function(element) { var index = this.indexOf(element); if (index > -1) { this.splice(index, 1); } else { console.error("Element not part of array!", this, element); } } Array.prototype.contains = function(element) { var index = this.indexOf(element); return index > -1; } Math.clamp = function(number, min, max) { return Math.min(max, Math.max(min, number)); }