Hello!
Simply it took me a little while to fully grasp the Stand In Line question so I decided to spend even more time on it to try and make it intuitive/fall out of love with javascript.
So essentially I tried the excercise in reverse, shifting the array first before returning a push. However one interaction that I’m not certain of is when I input a value into the push function, the console.log returned a later value, almost as if shift had been executed twice, relative to only once if the there was no value in the push function. Code below:
function test(para1, para2){
para1.shift(para2);
return para1.push(para2);
}
var testArr = [1,2,3];
console.log(testArr);
console.log(test(testArr, 4));
console.log(testArr);
Returns
>[1, 2, 3]
>3
>[2, 3, 4]
Whilst
function test(para1, para2){
para1.shift(para2);
return para1.push();
}
var testArr = [1,2,3];
console.log(testArr);
console.log(test(testArr, 4));
console.log(testArr);
returns:
>[1, 2, 3]
>2
>[2, 3]
Any idea why this is the case? As far as I can see in both instances the shift function should only iterate once in both instances, but it appears to iterate twice in the first example.
Kind regards!