I was doing leetcode and when i send value to a function (example: function(x)) it uses less memory and gives shorter runtime than doing otherwise (example: function()). Is that supposed to be like that?
This code uses more memory and has longer runtime:
var createCounter = function(init) {
let value = init;
const firstValue = init;
return {
increment(){
++value;
return value;
},
decrement(){
--value;
return value;
},
reset(){
value = firstValue;
return value;
}
}
};
This code uses less memory and has shorter runtime:
var createCounter = function(init) {
let value = init;
const firstValue = init;
return {
increment(init){
++value;
return value;
},
decrement(init){
--value;
return value;
},
reset(init){
value = firstValue;
return value;
}
}
};
I don’t really understand why.