NAME

position - find indices of items in an array

SYNOPSIS

arr.position(items)

DESCRIPTION

The position() method searches for items within arr. If items is a scalar, it returns the index of the first occurrence of items in arr, or -1 if not found. If items is an array, it returns an array of indices corresponding to the position of each element of items in arr. Note that it is possible to find entire sub-arrays of arr but the items must be enclosed in a generic List or Array of items with a rank exactly one less than that of arr.

This is similar to APL arr val

RETURN VALUE

An integer index or an array of integer indices.

ERRORS

ArgCheck if exactly one argument is not provided. TypeCheck if arr is not an array.

EXAMPLE

    a = {"apple", "orange", "banana"}
    a.position("orange")
1

    a.position({"banana", "pear"})
2 -1

    a = [3,3].iterate()
    a.position({[3,4,5]})
1

    a.position({[0,1,2],[6,7,8]})
0 2

SEE ALSO

member
unique