0
const sequenceSum = (b, e, s) => +(b <= e) && b + sequenceSum(b+s, e, s);

I don't understand how the plus sign before the test along with && evaluates. The expectation is that this function will in fact return one or the other rather then "this and this". If b <= e then the function is expected to return 0.

janat08
  • 1,367
  • 2
  • 11
  • 24
  • 2
    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Unary_plus – Keiwan Jan 14 '17 at 11:57
  • [What does this symbol mean in JavaScript?](http://stackoverflow.com/questions/9549780/what-does-this-symbol-mean-in-javascript) – Quentin Jan 14 '17 at 11:58
  • I unclear about the purpose of getting 0 or 1 out of the test. – janat08 Jan 14 '17 at 12:00
  • In that case the question falls back to [Logical AND](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_Operators#Logical_AND_()) – Teemu Jan 14 '17 at 12:01
  • So it takes 0 for false and will "preffer" that to the recursion return? Or in fact will also return that last value of the && values should the first test evaluate to true. – janat08 Jan 14 '17 at 12:07

0 Answers0