//input: an object with x and y properties //output: a normalized vector var normal = function(vector) { var length = Math.pow(Math.pow(vector.x, 2) + Math.pow(vector.y, 2), 0.5); if (length === 0) { return {x:0, y:0}; } else { return {x:(vector.x / length), y:(vector.y / length)}; } }; //input: x and y //output: the angle in radians var angle = function(x, y) { var theta = Math.atan(y / x); if (x < 0) { theta += Math.PI; } else if (y < 0) { theta += 2*Math.PI; } return theta; }; //remove all instances of input value from array Array.prototype.cleanse = function (value) { for (var i = 0; i < this.length - 1;) { if (this[i] === value) { this.splice(i, 1); } else { ++i; } } }; //creates the Array.isArray(obj) if it's not supported if (!Array.isArray) { Array.isArray = function (vArg) { return Object.prototype.toString.call(vArg) === "[object Array]"; }; } Array.prototype.removegiven = function (key, values) { if (Array.isArray(values)) { for (var j = 0; j <= values.length - 1; j++) { for (var k = 0; k <= this.length - 1; k++) { if (this[k][key] === values[j]) { this.splice(k, 1); } } } } else { for (var l = 0; l <= this.length - 1;) { if (this[l][key] === values) { this.splice(l, 1); } else l++; } } }