Permalink
Browse files

length filter should return length of objects as well

  • Loading branch information...
1 parent 619898c commit 944516bc0b14ce81d1b37122f1337529342148b7 @paularmstrong committed Sep 20, 2011
Showing with 7 additions and 4 deletions.
  1. +4 −0 lib/filters.js
  2. +3 −4 tests/filters.test.js
View
@@ -71,6 +71,10 @@ exports.last = function (input) {
};
exports.length = function (input) {
+ if (typeof input === 'object') {
+ return _.keys(input).length;
+ }
+
return input.length;
};
View
@@ -106,10 +106,9 @@ exports.json_encode = function (test) {
};
exports.length = function (test) {
- var input = [1, 2, 3];
- test.strictEqual(3, filters.length(input));
- input = 'foobar';
- test.strictEqual(6, filters.length(input));
+ test.strictEqual(3, filters.length([1, 2, 3]));
+ test.strictEqual(6, filters.length('foobar'));
+ test.strictEqual(2, filters.length({ 'h': 1, 'b': 2 }));
test.done();
};

0 comments on commit 944516b

Please sign in to comment.