The OpenD Programming Language

minmaxIndex

Finds a backward indices such that slice[indices[0]] is minimal and slice[indices[1]] is maximal elements in the slice.

template minmaxIndex(alias pred = "a < b")
static if(__traits(isSame, naryFun!pred, pred))
size_t[N][2]
minmaxIndex
(
Iterator
size_t N
SliceKind kind
)
(
Slice!(Iterator, N, kind) slice
)

Members

Functions

minmaxIndex
size_t[N][2] minmaxIndex(Slice!(Iterator, N, kind) slice)

Parameters

pred

A predicate.

Examples

import mir.ndslice.slice: sliced;
auto s = [
    2, 6, 4, -3,
    0, -4, -3, 3,
    -3, -2, 7, 8,
    ].sliced(3, 4);

auto indices = s.minmaxIndex;

assert(indices == [[1, 1], [2, 3]]);
assert(s[indices[0]] == -4);
assert(s[indices[1]] ==  8);

See Also

Meta