last
Returns the last or the N last elements of an ordered container.
Syntax
-
last(X)
-
X
is an ordered container
-
The returned value is an lvalue.
-
last(X, n)
-
X
is an ordered container -
n
is a non-negative integer
-
Description
-
If
X
is any ordered container (string, vector, matrix, list, structure, pixmap, or binary data object), thenlast(X)
returns the last element ofX
. -
last(X, n)
returns the lastn
elements ofX
, in order. IfX
is a linear container, then the type of the result is the type ofX
. Otherwise (ifX
is a matrix or a pixmap) the result is a list.
Examples
sort(frequencies(compute(RandomInt(1000000)^2, n, 1, 1000000) @ digits @ last))
(0, 99581) (1, 200067) (4, 200294) (5, 99928) (6, 200237) (9, 199893)
Alice ≔ ExampleData("Alice in Wonderland") \ 50
ALICE’S ADVENTURES IN WONDERLAND Lewis Carroll …
sort(frequencies(words(Alice) @ characters @ last @ UpperCase))
(A, 679) (B, 5) (C, 8) (D, 3207) (E, 5732) (F, 836) (G, 1018) (H, 658) (I, 415) (K, 379) (L, 671) (M, 332) (N, 1791) (O, 1314) (P, 209) (Q, 1) (R, 1504) (S, 2211) (T, 3266) (U, 363) (V, 2) (W, 356) (X, 15) (Y, 1416)
last(ColorGradient(1, 10, "white", "black"), 3)
rgba(0.224, 0.224, 0.224, 1.000) rgba(0.110, 0.110, 0.110, 1.000) rgba(0.000, 0.000, 0.000, 1.000)