Ad
  • Custom User Avatar

    Math.pow(a, b)

  • Custom User Avatar

    Best of the best is COBOL:

          CALL "MY-BLOODY-FUNCTION" USING BY CONTENT TABLE-OF-STUFF
                                          BY REFERENCE TABLE-MUTABLE
    

    (works with numbers, strings... whatever)

  • Default User Avatar

    I agree with you. the terminoloty is misleading.
    the argument contains a reference to a object, u can change the content of the argument, but at end of the function the argument points to the same memory address. in C++ this is more clear, beacause u have the "&" reference operador, then u can pass the address of the argument itself, in this way, u can change the address the argument points.

    then, in C++ u can assingn new values for dest and source within the function of the problem.

    Thanks for the answers, talk about this things, improve the understading of the subject.

  • Default User Avatar

    I think we both understand how parameters are passed in JS, we just disagree on the terminology. It sounds silly to me to say that an object is "passed by value" when I can mutate the original object from within the function (i.e. the function has side effects).

    Going by your definition, only languages like PHP have something like "passing by reference", where using the assignment operator (=) affects the original variable.
    I think a better term for how objects are passed in JS / Python / Java ... is 'call by sharing'.

    If you say that in JS, both Numbers and Objects are passed by value, it sounds really misleading with regard to purity and side effects : in one case the function is pure, in the other it's not, and you have to watch out for mutation when you pass your object to a function.

    Anyway, let's not bicker about it, I dont want to argue endlessly on terminology, as long as we both understand what's happening.

  • Custom User Avatar
  • Default User Avatar

    I guess you misunderstand the fact of the passage by reference you pass a reference to parameter, the address of a paramenter, not the address to object pointed, the parameter contain a address for object, but passage by reference pass a reference for a parameter, in this case you can change the paremeter itself.

    google it:
    "
    The parameters, in a function call, are the function's arguments. JavaScript arguments are passed by value: The function only gets to know the values, not the argument's locations. If a function changes an argument's value, it does not change the parameter's original value.
    "

  • Default User Avatar

    you CAN change the object passed to your function precisely because it is passed by reference, not by value ...

  • Default User Avatar

    Yes, it is the concept of pass by value, we can change the object in memory, but the parameter at the end of function pointers to the same memory address.
    Otherwise, by reference, you could change the object pointed and the parameter itself.

  • Default User Avatar

    JS parameters are always passed by value

    are they really ?

    function modify (array) { array[0] = "mutated !" };
    const array = ["hello world"];
    modify(array);
    console.log(array[0]); // 'mutated !'
    

    objects are passed by a copy of the reference. this means reassigning to the parameter will indeed have no effect on the original object; however, modifying the object's properties will affect the original object

  • Default User Avatar

    It's a great Kata, I learned alot about JavaScript.

    JS parameters are always passed by value, this increase the difficult of the problem, you have to discover a solution for this.

    assign values to dest or source does not work within the function.

  • Default User Avatar

    Wow! beautiful, this is so good!

  • Default User Avatar

    Congratz, Very classy solution

  • Default User Avatar
  • Default User Avatar

    this is so beautiful, like o poem.

  • Default User Avatar
  • Loading more items...