1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
The `unshift()` function places the given argument(s) at the begin of the
given array while maintaining their order.
Returns the last added value.
Returns `null` if the given destination argment is not an array.
Throws a type exception if the given array is immuatable.
-- Testcase --
{%
let arr = [];
printf("%.J\n", [
// add one element
unshift(arr, 123),
// add multiple elements
unshift(arr, 1, 2, 3),
// add null values
unshift(arr, null, null, 4),
// no-op
unshift(arr),
// invalid destination
unshift({}, 1, 2, 3)
]);
printf("%.J\n", arr);
%}
-- End --
-- Expect stdout --
[
123,
3,
4,
null,
null
]
[
null,
null,
4,
1,
2,
3,
123
]
-- End --
|