slice_array

Description

Given an array, returns a possibly smaller array, starting at the given from index, and including items up to but not including the to index. Indices start counting at 0; 0 is the first element. Negative indices start counting at the end; -1 is the last element (not the end of the array!)

When only two arguments are supplied, the array starting at the given from index and ranging to the end of the input is returned. Thus, slice_array(ary, 1) will remove the first element from an array.

A slice where the to element is the same as, or earlier than, the from element, will return an empty array. Similary, if starting to slice after the end of the array, or ending the slice before the start of the array, an empty array will be returned.

The from and to values must be constant at compile time.

Return type

array

Domain

This is a scalar function (calculates a single output value for a single input row.)

Categories

Usage

slice_array( array, start [ , end ] )

Argument

Type

Required

Multiple

array

array

Required

Only one

start

int64

Required

Only one

end

int64

Optional

Only one

Examples

make_col arr:slice_array(make_array('a','b','c','d'), 1, 2)

Make a new column arr which contains the array ['b'], becaue it starts at element 1, which is ‘b’, and it stops before element 2, which is ‘c’.

make_col arr:slice_array(make_array('a','b','c','d'), -2)

Make a new column arr which contains the array ['c', 'd'], becaue it starts at element 2 from the end, which is ‘c’, and runs to the end of the array.