Ad
  • Custom User Avatar

    thank you for this comment. My friend told me "you wont be able to do this challenge" so of course I've been trying extra hard not to look at the solutions. I wrote several different permutations but it just seemed impossible to both return the answer AND the reference to the next function. This comment seems to confirm for me that it is indeed impossible to complete this as described. If I understand properly, the solution is to manipulate the prototype of the returned function such that functions which evaluate it see the answer we've stored, but this is something I considered and dismissed as it does not fulfill the instructions as I read them :(

    Am i understanding this right?

  • Custom User Avatar

    Good point. This method is new to me. Thanks for the explaination.

  • Default User Avatar
  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    I only solved the python one but am a JS dev. So out of curiosity does it fail if you do strict comparison using === ?

  • Custom User Avatar

    in fact, the premise of the question is not right

    "add(1)(2);
    // returns 3"

    No. It is not. This returns a function.

    In the tests, it is the == operator that does the conversion, as you can read it here:

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Equality

    "If the operands are of different types, try to convert them to the same type before comparing:
    When comparing a number to a string, try to convert the string to a numeric value.

    • If one of the operands is Boolean, convert the Boolean operand to 1 if it is true and +0 if it is false.
    • If one of the operands is an object and the other is a number or a string, try to convert the object to a primitive using the object's valueOf() and toString() methods."
  • Custom User Avatar

    I was heading towards this solution, but I didn't finish...

    Great clever work!

  • Custom User Avatar