Ad
  • Default User Avatar

    Insert a print statement at the beginning of the function. It will print the random test case.

  • Custom User Avatar

    JS, unlike other langs such as Haskell, has no builtin lazy evaluation support
    Which means all arguments will be evaluated before passing them to the function
    Also, replace only takes two does not means other arguments will not be evaluated
    So, given

    (ExprA).Method((ExprB),(ExprC),(ExprD))
    

    You can transform it into an equivalent form

    RstA = ExprA
    Method = RstA.Method
    RstB = ExprB
    RstC = ExprC
    RstD = ExprD
    // Note the evaluattion order before this line is important, and will not be changed crossing any JS implementation
    Method.call(RstA,RstB,RstC,RstD)
    
  • Custom User Avatar

    You can feed any number of arguments to any functions as you like, and they only care about just the amount they required
    Which means it.replace(a,b,c,d,e) has nothing different with it.replace(a,b) in the view of replace method

    PS. Actually there is a limit of arguments number depends on the implementation. Like if you feed too much to a function in the latest Chrome, you will get SyntaxError: Too many arguments in function call (only 65535 allowed)