From 0d8e1e624005b58aecd6a6dddaefc20da33cdf4a Mon Sep 17 00:00:00 2001 From: James Halliday Date: Wed, 8 Sep 2010 15:42:06 -0800 Subject: [PATCH] compact like in ruby, but for hashes --- lib/hash.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/hash.js b/lib/hash.js index db3395b..0c9c2a2 100644 --- a/lib/hash.js +++ b/lib/hash.js @@ -85,6 +85,10 @@ function Hash (hash, extra) { return memoized.values; } }); + Object.defineProperty(self, 'compact', { get : function () { + return Hash(hash).filter(function (x) { return x !== undefined }); + } }); + Object.defineProperty(self, 'clone', { get : function () { return Hash(Hash.clone(hash)); } });