Javascript Array takeWhile(predicate)
Array.prototype.takeWhile = function (predicate) { predicate = predicate || Predicate;/*from w w w . j a v a2 s .c o m*/ var l = this.length; var arr = []; for (var i = 0; i < l && predicate(this[i], i) === true ; i++) arr.push(this[i]); return arr; };