pop . array . sncode
POP
NAME
pop - Removes the last element from array and returns it.
SYNOPSIS
pop(array)
pop(array, elem1, ...)
DESCRIPTION
This function removes the last element of an array. and returns it.
So if a = [1,2,3,4,5]; pop(a) return 5 and a has value 1,2,3,4.
In the second form, pop remove the element based on the position starting at zero.
If the value of elem is less than zero, it will remove the element based on the position from the end starting at 1.
The second form is available from version 5.89
EXAMPLES
a = [1,2,3,4,5]; a.top(); a.last(); a.shift(); a; a.pop(); a; will return es=151[2,3,4,5]5[2,3,4].
a = [1,2,3,4,5];
a.pop(-2,-4);
a;
return res=[4,2][1,3,5].
a = [1,2,3,4,5];
a.pop(-2,-100);
a;
return array is size 5 and you try to remove element -100
a = [1,2,3,4,5];
a.pop(2,3);
a;
return res=[3,4][1,2,5].
a = [1,2,3,4,5];
a.pop(0,1, 2,3);
a;
return res=[1,2,3,4][5].
a = [1,2,3,4,5];
a.pop(0,1, 2,3,4);
a;
return res=[1,2,3,4,5][].
a = [1,2,3,4,5];
a.pop(0,1, 2,3,4,5);
a;
return array is size 5 and you try to remove element 5
a = [1,2,3,4,5];
a.pop(2,3, 10);
a;
return array is size 5 and you try to remove element 10
a = [1,2,3,4,5];
a.pop(2,3, -10);
a;
return array is size 5 and you try to remove element -10
AUTHOR
Written by Pierre Laplante and Caroline Laplante, <laplante@sednove.com>