Ad
  • Default User Avatar

    Yeah, passing an object with key-value pairs would be the easiest (and proper) way to give a function "named arguments". I.e., you'd change the function from function fnname(arg1, arg2) to function fnname({arg1, arg2}), and change the code that calls it from fnname(val1, val2) to fnname({arg1: val1, arg2: val2}).

    However, the kata challenge here was to hotfix a pre-existing function that takes ordinary arguments, so it implies that you can't or aren't supposed to modify the function... you're just supposed to wrap it in a new anonymous function that figures out what arguments it expects and provides defaults.

  • Custom User Avatar

    The usual way to do this now seems to be using an object at the end of the arguments to store named arguments, kind of like kwargs dict in Python.

  • Custom User Avatar

    Not an issue

  • Custom User Avatar

    Not an issue

  • Custom User Avatar

    Added

  • Custom User Avatar

    Yes

  • Custom User Avatar

    You're not handling closures correctly.

  • Custom User Avatar

    No.

  • Default User Avatar

    I'm getting this error on test 23 it says ReferenceError: five is not defined at eval at /home/codewarrior/index.js:90:52 at /home/codewarrior/index.js:115:5 at Object.handleError
    and the func passed into default arguments is var timesFive = function () { var five = 5; return function (a) { return five * x; }; }(); function (n) { return five * n; } which seems wrong.