Permalink
Browse files

Handle lots of spaces

  • Loading branch information...
1 parent e6c93d0 commit 31e26d878f3c96e58d017df84a8aaea9698822b2 @matholroyd committed Mar 4, 2012
Showing with 7 additions and 1 deletion.
  1. +1 −1 javascript/lyahfgg/chapter-10.js
  2. +6 −0 javascript/lyahfgg/chapter-10.spec.js
@@ -8,7 +8,7 @@ exports.solveRPN = function(equation) {
}
}
- var terms = equation.split(' '),
+ var terms = equation.trim().split(/\s+/),
a = parseFloat(terms[0]),
b = parseFloat(terms[1]),
op = get_operator(terms[2]);
@@ -9,4 +9,10 @@ describe("Reverse Polish Notation", function() {
expect(chapter10.solveRPN("2 5 *")).toEqual(10);
});
+ describe("with dodgy input", function() {
+ it("can handle too many spaces", function () {
+ expect(chapter10.solveRPN(" 2 5 *")).toEqual(10);
+ });
+ });
+
});

0 comments on commit 31e26d8

Please sign in to comment.