Modify or not modify your objects when creating computing functions? See the examples below:

function map_cloning(obj,fn){
    result = {};
    for (var key in obj)
        result[key] = fn(obj[key]);
    return result;
};
function map_modifying(obj,fn){
    for (var key in obj) 
        obj[key] = fn(obj[key]);
    return obj;
};

function sum_cloning(vector1,vector2){
    return [vector1[0] + vector1[1], vector2[0] + vector2[1]];
};
function sum_modifying(vector1,vector2){
    vector1.x += vector2.x;
    vector1.y += vector2.x;
    return vector1;
};

function tail_cloning(obj){
    return obj.slice(1);
};
function tail_modifying(obj){
    obj.splice(0,1);
    return obj;
};


Often you have to chose between cloning or not an object before making a computation. Which is best?
I suggest cloning. If it was possible (like in Java), I'd even suggest making your objects immutable...

Why do I suggest cloning? Consider being after a busy Friday, with business users ranting all day on some totally unimportant feature, and you see this code fragment all of a sudden, having a, b and c variables:

b=sum_modifying(a,b);
 //some other code here
a=sum_modifying(c,a);
 //some other code here
b=sum_modifying(c,a);


Will you be able to track back what's going on? I woudn't, for sure...

Even this is a tough situation, but at least, the value of the variables change only with the assignment.

b=sum_cloning(a,b);
 //some other code here
a=sum_cloning(c,a);
 //some other code here
b=sum_cloning(c,a);


However, I'd suggest a third alternative: add functions to the objects themselves, to enable schemes like this:

result = a.add(b);


I'd find this the most readable of these.
(I stole the idea mainly from Java's BigDecimal.)