This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Fix `add` filter when adding numbers/numbers+strings together.

  • Loading branch information...
paularmstrong committed Dec 22, 2011
1 parent 648c455 commit cb82fc8983f377d18c4c6846a4e57da14278c39e
Showing with 3 additions and 5 deletions.
  1. +2 −5 lib/filters.js
  2. +1 −0 tests/filters.test.js
View
@@ -11,11 +11,8 @@ exports.add = function (input, addend) {
return _.extend(input, addend);
}
- var inputNum = parseInt(input, 10),
- addendNum = parseInt(addend, 10);
-
- if (_.isNumber(inputNum) && _.isNumber(addendNum)) {
- return inputNum + addendNum;
+ if (_.isNumber(input) && _.isNumber(addend)) {
+ return input + addend;
}
return input + addend;
View
@@ -9,6 +9,7 @@ function testFilter(test, filter, input, output, message) {
exports.add = function (test) {
testFilter(test, 'add(2)', { v: 1 }, '3', 'add numbers');
+ testFilter(test, 'add(2)', { v: '1' }, '12', 'string number is not real number');
testFilter(test, 'add([3, 4])', { v: [1, 2] }, '1,2,3,4', 'arrays add from literal');
testFilter(test, 'add(b)', { v: [1, 2], b: [3, 4] }, '1,2,3,4', 'arrays add from var');
testFilter(test, 'add(2)', { v: 'foo' }, 'foo2', 'string var turns addend into a string');

0 comments on commit cb82fc8

Please sign in to comment.