My code currently looks like this
numbers = [1, 2, 3, 4, 5]
def pop_three
pop = []
3.times { pop << numbers.pop }
return pop
end
Is there any way to do what's inside the pop_three
method in one line?
I basically want to do something like numbers.slice(0, 3)
but deleting the array items that are in the slice.
Uhm...hrmmm, I think I just realized I can try slice!
Yes
numbers.pop(3)
Or
numbers.shift(3)
If you want this other side.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With