(09-22-2015 11:06 AM)Tyann Wrote: Hello
What would be great also:
Insert ( list , position ,value or list )
and
Delete (list, position, [ number of elements ] )
please
Here are two functions doing that:
Code:
// Insert 'value' at 'position' in 'list'. Value can be a list or a single value.
// If position is <=1, value is inserted at the beginning of the list
// If position is after the last element of the list, value is inserted at the end of the list
EXPORT InsList(list,position,value)
BEGIN
CASE
IF position<=1 THEN CONCAT(value,list);END;
IF position>SIZE(list) THEN CONCAT(list,value);END;
DEFAULT CONCAT(CONCAT(list({1,position-1}),value),list({position,SIZE(list)}));
END;
END;
Code:
// Delete a 'qty' of elements from 'list' starting at 'position'.
// The elements to be deleted are at the intersection of [1,size(list)] and [position, position+qty-1]
// for ex. DelList({1,2,3,4},0,3) deletes the first and second elements of the list and returns {3,4}
EXPORT DelList(list,position,qty)
BEGIN
LOCAL lb,le;
IFTE(position<=1,lb:={}, lb:=list({1,position-1}));
IFTE(position+qty>SIZE(list), le:={}, le:=list({position+qty,SIZE(list)}));
CONCAT(lb,le);
END;