-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patharray.bas
95 lines (86 loc) · 1.71 KB
/
array.bas
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
' Array
def indexOf(array[], num)
var i
for i = 0 to len(array) - 1
if array[i] == num then return i
next
return -1
end
def indexOf$(array$[], string$)
var i
for i = 0 to len(array$) - 1
if array$[i] == string$ then return i
next
return -1
end
def implode$(array$[], glue$)
var i
var rv$
for i = 0 to len(array$) - 1
if i == 0 then
rv$ = array$[i]
else
rv$ = rv$ + glue$ + array$[i]
endif
next
return rv$
end
def arrayToStr$(array$[])
var i
var rv$
for i = 0 to len(array$) - 1
if i == 0 || array$[i] == "]" || (i > 0 && array$[i-1] == "[") then
rv$ = rv$ + array$[i]
else
rv$ = rv$ + "," + array$[i]
endif
next
return rv$
end
def arrDump array$[]
? "size: " + str$(arrSize(array$))
? "elements: " + arrayToStr$(array$)
end
def arrFlatten$(array$[])
var i
dim arr$[0]
for i = 0 to len(array$) - 1
if array$[i] != "[" && array$[i] != "]" then push arr$, array$[i]
next
return arr$
end
def arrSize(array$[])
array$ = arrFlatten$(array$)
return len(array$)
end
def arrJoin(array$[], glue$)
var i
var rv$
for i = 0 to len(array$) - 1
if array$[i] != "[" && array$[i] != "]" && rv$ == "" then
rv$ = rv$ + array$[i]
elseif array$[i] != "[" && array$[i] != "]" && rv$ != "" then
rv$ = rv$ + glue$ + array$[i]
endif
next
return rv$
end
def arrUniq$(array$[])
var i
var dimension = 1
dim comparison$[0]
for i = 0 to len(array$) - 1
if array$[i] == "[" then
inc dimension
push comparison$, "["
elseif array$[i] == "]" then
dec dimension
push comparison$, "]"
elseif dimension == 1 && indexOf$(comparison$, array$[i]) == -1 then
push comparison$, array$[i]
elseif dimension > 1 then
push comparison$, array$[i]
endif
next
return comparison$
end