Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Dec 6th, 2018 50 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. //function extensions
  2. Function.prototype.addMethod = function(name, func){
  3.     if(!this.prototype[name]){
  4.         this.prototype[name] = func;
  5.     }
  6.     return this;
  7. };
  8.  
  9. //number extensions
  10. Number.addMethod('toInteger', function(){
  11.     return Math[this < 0 ? 'ceil' : 'floor'](this);
  12. });
  13.  
  14. //string extensions
  15. String.addMethod('trim', function(){
  16.     return this.replace(/^\s+|\s+$/g, '');
  17. });
  18.  
  19. String.addMethod('insertAt', function(loc, strChunk){
  20.     var val = this.valueOf().substr(0, loc);
  21.     return val + strChunk + this.valueOf().substr(loc);
  22. });
  23.  
  24. //array extensions
  25. Array.addMethod('toSet', function(){
  26.     for(var i=0; i < this.length; i++){
  27.          var val = this[i];
  28.          for(var j=i+1; j < this.length; j++)
  29.             if(this[j]==val)
  30.                 this.splice(j--, 1);
  31.     }
  32.     return this;
  33. });
  34.  
  35. //first class functions
  36. var range = function(start, end, step){
  37.     if(step === undefined){
  38.         var step = 1;
  39.     }
  40.  
  41.     var nums = [];
  42.     while(a != b){
  43.         nums.push(a);
  44.         a += step;
  45.     }
  46.     return nums;
  47. };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top