3
0
mirror of https://github.com/reality/dbot.git synced 2024-11-23 20:39:25 +01:00

More efficient snippets

This commit is contained in:
Luke Slater 2011-08-26 12:45:49 +01:00
parent 34e9f9b036
commit 908e957db1

View File

@ -39,49 +39,26 @@ String.prototype.valMatch = function(regex, expLength) {
}; };
String.prototype.endsWith = function(needle) { String.prototype.endsWith = function(needle) {
var end = this.slice(this.length - needle.length); return needle === this.slice(this.length - needle.length);
if(needle === end) {
return true;
} else {
return false;
}
}; };
String.prototype.startsWith = function(needle) { String.prototype.startsWith = function(needle) {
var start = this.slice(0, needle.length); return needle === this.slice(0, needle.length);
if(needle === start) {
return true;
} else {
return false;
}
}; };
/*** Object ***/ /*** Object ***/
Object.prototype.isFunction = function(obj) { Object.prototype.isFunction = function(obj) {
if(typeof(obj) == 'function') { return typeof(obj) === 'function';
return true;
} else {
return false;
}
}; };
Object.prototype.isArray = function(obj) { Object.prototype.isArray = function(obj) {
if(Object.prototype.toString.call(obj) === '[object Array]') { return Object.prototype.toString.call(obj) === '[object Array]';
return true;
} else {
return false;
}
}; };
/*** Integer ***/ /*** Integer ***/
Number.prototype.chanceIn = function(x, y) { Number.prototype.chanceIn = function(x, y) {
var num = Math.floor(Math.random() * (y + 1)) / x; var num = Math.floor(Math.random() * (y + 1)) / x;
console.log(num); return num == 1;
if(num == 1) {
return true;
} else {
return false;
}
}; };