Moved prototype extenders to utils.js

This commit is contained in:
Bram van der Veen 2016-06-28 16:16:05 +02:00
parent 9c8274d227
commit 555e2f3345
2 changed files with 26 additions and 26 deletions

View file

@ -62,30 +62,4 @@ function generate() {
console.log('generate elapsed', (((new Date()).getTime() - start) * 0.001).toFixed(3) + "s"); console.log('generate elapsed', (((new Date()).getTime() - start) * 0.001).toFixed(3) + "s");
} }
Array.prototype.indexContains = function(word) {
for (var idx = 0; idx < this.length; idx++) {
var test = this[idx];
if (test.indexOf(word) >= 0 || word.indexOf(test) >= 0) {
return idx;
}
}
return -1;
}
Math.clamp = function(a, min, max) {
return a < min ? min : (a > max ? max : a);
};
Array.prototype.insertAt = function(where, what) {
if (where < 0) {
this.splice(0, 0, what);
} else {
var tail = this.splice(where);
this.push(what)
for (var i = 0; i < tail.length; i++) {
this.push(tail[i]);
}
}
}
generate(); generate();

View file

@ -67,6 +67,32 @@ function kappatalize(str) {
return str.charAt(0).toUpperCase() + str.slice(1); return str.charAt(0).toUpperCase() + str.slice(1);
} }
Array.prototype.indexContains = function(word) {
for (var idx = 0; idx < this.length; idx++) {
var test = this[idx];
if (test.indexOf(word) >= 0 || word.indexOf(test) >= 0) {
return idx;
}
}
return -1;
}
Math.clamp = function(a, min, max) {
return a < min ? min : (a > max ? max : a);
};
Array.prototype.insertAt = function(where, what) {
if (where < 0) {
this.splice(0, 0, what);
} else {
var tail = this.splice(where);
this.push(what)
for (var i = 0; i < tail.length; i++) {
this.push(tail[i]);
}
}
}
module.exports = { module.exports = {
"random_name": random_name, "random_name": random_name,
"gravity": gravity, "gravity": gravity,