Suppose I want to write a function that removes all zeros in an Array.
var removeZero = function(nums) {
const nonZ = nums.filter(myFunc);
function myFunc(value) {
return value !== 0;
}
return nonZ;
}
The above code would work. Sure. Now I can just do the following and get an array without 0
var someNum = [2,0,9,0,0,34];
var someNum = removeZero(someNum);
Now my real question is, may I directly change the removeZero function's argument, and not have to create a nonZ and return it?
I wrote the following code but didn't work:
var removeZero = function(nums) {
nums.filter(myFunc);
function myFunc(value) {
return value !== 0;
}
}
var someNum = [2,0,9,0,0,34];
removeZero(someNum); // this fails changing the someNum array
How can I solve this, thank you