From 26d79e318e80e141513e6ff63cb011014810e139 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sat, 22 Mar 2014 15:56:30 +0400 Subject: [PATCH] added Array.prototype.compact() method... Signed-off-by: Alex A. Naanou --- ui/lib/jli.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ui/lib/jli.js b/ui/lib/jli.js index 04699b7a..059233a2 100755 --- a/ui/lib/jli.js +++ b/ui/lib/jli.js @@ -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 }