Implementation of JavaScript shift() function


Took 13 minutes and 24 seconds to implement JavaScript shift() function. Here is the code snippet.

Function:
arr=['a', 'b', 'c'];

function shift(arr) {
for (var i = 0; i < arr.length; i++) {
arr[i] = arr[i+1];
}
arr.pop();
return arr;
}

shift(arr);
document.write(arr);

Result:
b,c

No comments:

Post a Comment

GITEX Dubai Talk by Saion Gupta and Saiasmi Gupta

Good morning, everyone. I'm Saion Gupta, the Founder of 10xCoderKids and the Guinness World Record holder for the youngest computer prog...