File tree Expand file tree Collapse file tree 2 files changed +52
-1
lines changed
Expand file tree Collapse file tree 2 files changed +52
-1
lines changed Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ An easy interpreter to learn.
2424
2525- Closure supported
2626
27- ![ example3 ] ( https://github.com/ivanallen/autumn/blob/master/docs/images/example4.png )
27+ ![ example4 ] ( https://github.com/ivanallen/autumn/blob/master/docs/images/example4.png )
2828
2929- ...
3030
@@ -83,6 +83,57 @@ $ DEBUG_AUTUMN=1 ./autumn parser
8383$ ./autumn eval
8484```
8585
86+ ## Demo
87+
88+ This is a quick sort source.
89+
90+ - You need a filter function
91+
92+ ``` js
93+ let filter = fn (arr , f ) {
94+ let iter = fn (arr , accumulated ) {
95+ if (len (arr) == 0 ) {
96+ accumulated
97+ } else {
98+ let e = if (f (first (arr))) {
99+ push (accumulated, first (arr));
100+ } else {
101+ accumulated
102+ }
103+ iter (rest (arr), e);
104+ }
105+ };
106+ iter (arr, []);
107+ };
108+ ```
109+
110+ - QuickSort
111+
112+ ``` js
113+ let quickSort = fn (arr ) {
114+ if (len (arr) == 0 ) {
115+ return arr;
116+ } else {
117+ let head = first (arr);
118+ let smaller = filter (rest (arr), fn (x ) { x <= head });
119+ let bigger = filter (rest (arr), fn (x ) { x > head });
120+ let smaller = quickSort (smaller);
121+ let bigger = quickSort (bigger);
122+ return quickSort (smaller) + [head] + quickSort (bigger);
123+ }
124+ }
125+ ```
126+
127+ - Test
128+
129+ ``` js
130+ let a = [4 ,5 ,3 ,4 ,6 ,6 ]
131+ quickSort (a)
132+ ```
133+
134+ ![ example5] ( https://github.com/ivanallen/autumn/blob/master/docs/images/example5.png )
135+
136+
86137## Contributor
87138
88139Allen.
You can’t perform that action at this time.
0 commit comments