History

reverse feature and unit test + example

Andrew Aday committed 3 years ago

Commit e7ef3c81 parent 7686e906 files · +122 −0Browse files

Showing the changes to examples/array (1 of 6 files). Show all

Unified · Split

examples/array/array_reverse.ck+26−0
@@ -0,0 +1,26 @@
1// example reversing the order of an array
2// version: need chuck-1.4.2.1 or higher
3
4// an array
5[1,2,3,4,5] @=> int a[];
6
7// print array in-order
8print_arr(a);
9
10// reverse
11a.reverse();
12
13// print reversed order
14print_arr(a);
15
16// return to original order
17a.reverse();
18print_arr(a);
19
20
21fun void print_arr(int a[]) {
22 for (0 => int i; i < a.size(); i++) {
23 cherr <= a[i] <= " ";
24 }
25 cherr <= IO.nl();
26}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t