[Solved] Javascript – What is wrong with my code?


Javascript works with pointer, so passing the array as a paramater will edit that array from where it was called.

This should do the job :

function queue(arr, item) {
    arr.push(item);
    return arr.shift();
}

var myArr = [1,2,3,4];
console.log("Before: " + JSON.stringify(myArr));
console.log(queue(myArr, 1)); // Modify this line to test
console.log("After: " + JSON.stringify(myArr));

0

solved Javascript – What is wrong with my code?