I'm currently working on an assignment for my JS course that involves creating a function using only .push and .pop commands. The task is to take the last value from the first array and move it to the second array. Unfortunately, I seem to be messing something up in my code.
Here's the example we were given to follow:
let anArray = [1, 2];
let anotherArray = [3, 4];
move(anArray, anotherArray);
anArray //should be [1]
anotherArray //should be [3,4,2]
And here's what I've attempted so far:
function move(parameter1, parameter2){
var anArray = [1, 2];
var anotherArray = [3, 4];
var storage = anArray.pop();
anotherArray.push(storage);
}
I'm seeking some guidance as to why my function doesn't seem to be working as expected. I'm fairly new to JavaScript, so any help would be greatly appreciated.
Thank you,
Luis.