added Array.prototype.compact() method...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2014-03-22 15:56:30 +04:00
parent c1c470f661
commit 26d79e318e

View File

@ -1112,9 +1112,17 @@ Object.get = function(obj, name, dfl){
}
// Compact a sparse array...
//
// NOTE: this will not compact in-place.
Array.prototype.compact = function(){
return list.filter(function(){ return true })
}
// like .length but for sparse arrays will return the element count...
Array.prototype.len = function(){
return this.filter(function(){ return true }).length
return this.compact().length
}