-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathexample.red
56 lines (49 loc) · 913 Bytes
/
example.red
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
53
54
55
56
Red [
description: {"Simple Linked List" exercise solution for exercism platform}
author: "loziniak"
]
to-array: function [
list [block! none!]
return: [vector!]
] [
array: make vector! []
while [not none? list] [
append array list/1
list: list/2
]
array
]
from-array: function [
array [vector!]
return: [block! none!]
] [
list: none
loop element: length? array [
list: reduce [array/(element) list]
element: element - 1
]
list
]
reverse-list: function [
list [block! none!]
return: [block! none!]
] [
reversed: none
while [not none? list] [
reversed: reduce [list/1 reversed]
list: list/2
]
reversed
]
from-array-and-back: function [
array [block!]
return: [block!]
] [
to block! to-array from-array make vector! array
]
convert-reverse-convert-back: function [
array [block!]
return: [block!]
] [
to block! to-array reverse-list from-array make vector! array
]