/ Published in: JavaScript
Expand |
Embed | Plain Text
//removes a section of the array, returning what's left; does not affect the original array //(essentially the opposite of Array.slice) //example: // var x = ['a', 'b', 'c', 'd']; // var y = x.prune(1,3); // alert(x); //['a', 'b', 'c', 'd'] // alert(y); //['a', 'd'] //end argument is optional Array.prototype.prune = function(start, end) { var result = this.slice(0, start); if(!isNaN(end)) result.concat(this.slice(end)); return result; }
You need to login to post a comment.
