From 908e957db11d2a87182dc2d1fdff9b478197f555 Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Fri, 26 Aug 2011 12:45:49 +0100 Subject: [PATCH] More efficient snippets --- snippets.js | 33 +++++---------------------------- 1 file changed, 5 insertions(+), 28 deletions(-) diff --git a/snippets.js b/snippets.js index d357efb..d845ad9 100644 --- a/snippets.js +++ b/snippets.js @@ -39,49 +39,26 @@ String.prototype.valMatch = function(regex, expLength) { }; String.prototype.endsWith = function(needle) { - var end = this.slice(this.length - needle.length); - if(needle === end) { - return true; - } else { - return false; - } + return needle === this.slice(this.length - needle.length); }; String.prototype.startsWith = function(needle) { - var start = this.slice(0, needle.length); - if(needle === start) { - return true; - } else { - return false; - } + return needle === this.slice(0, needle.length); }; /*** Object ***/ Object.prototype.isFunction = function(obj) { - if(typeof(obj) == 'function') { - return true; - } else { - return false; - } + return typeof(obj) === 'function'; }; Object.prototype.isArray = function(obj) { - if(Object.prototype.toString.call(obj) === '[object Array]') { - return true; - } else { - return false; - } + return Object.prototype.toString.call(obj) === '[object Array]'; }; /*** Integer ***/ Number.prototype.chanceIn = function(x, y) { var num = Math.floor(Math.random() * (y + 1)) / x; - console.log(num); - if(num == 1) { - return true; - } else { - return false; - } + return num == 1; };