Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

adding reverse filter

  • Loading branch information...
commit 0ed82ae4073677d9b74842f55427cb06fe5689e3 1 parent a9d77a0
@paularmstrong paularmstrong authored
Showing with 15 additions and 0 deletions.
  1. +8 −0 lib/filters.js
  2. +7 −0 tests/filters.test.js
View
8 lib/filters.js
@@ -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;
};
View
7 tests/filters.test.js
@@ -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));
Please sign in to comment.
Something went wrong with that request. Please try again.