I have the following function.
const array = [1, 2, 3];
// Impure function
function addElementToArray(element) {
array.push(element);
}
This is an impure function because it mutates the global array. So, I thought that giving the whole array as a function argument will make the function pure.
function addElement(array, element) {
array.push(element);
}
But, I found that it has also side effects.
so, what would be the best approach to make it a pure function?