javascript - Is there a way to method chain .push and .shift array methods? -
here's code:
var myarr = [1,2,3,4,5]; function queue(arr, item) { return arr.push(item).shift(); } i'm attempting create function queue takes "array" , "item" arguments. need to
- add item onto end of array
- remove first element of array
- return element removed.
my code not working. can me figure out?
because arr.push returns length of array, can't chain shift that
simply this
function queue(arr, item) { arr.push(item); return arr.shift(); }
Comments
Post a Comment