Skip to content

Commit

Permalink
adding reverse filter
Browse files Browse the repository at this point in the history
  • Loading branch information
paularmstrong committed Aug 12, 2011
1 parent a9d77a0 commit 0ed82ae
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@ exports.join = function (input, separator) {
}
};

exports.reverse = function (input) {
if (Array.isArray(input)) {
return input.reverse();
} else {
return input;
}
};

exports.length = function (input) {
return input.length;
};
Expand Down
7 changes: 7 additions & 0 deletions tests/filters.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ exports.join = function (test) {
test.done();
};

exports.reverse = function (test) {
test.deepEqual([3, 2, 1], filters.reverse([1, 2, 3]), 'reverse array');
test.strictEqual('asdf', filters.reverse('asdf'), 'reverse string does nothing');
test.deepEqual({ 'foo': 'bar' }, filters.reverse({ 'foo': 'bar' }), 'reverse object does nothing');
test.done();
};

exports.length = function (test) {
var input = [1, 2, 3];
test.strictEqual(3, filters.length(input));
Expand Down

0 comments on commit 0ed82ae

Please sign in to comment.