You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 29, 2025. It is now read-only.
---Removes the last element from an array and returns the removed element.
132
160
functionlib.array:pop()
133
161
returntable.remove(self)
@@ -147,11 +175,6 @@ function lib.array:push(...)
147
175
returnlength
148
176
end
149
177
150
-
---Removes the first element from an array and returns the removed element.
151
-
functionlib.array:shift()
152
-
returntable.remove(self, 1)
153
-
end
154
-
155
178
---The "reducer" function is applied to every element within an array, with the previous element's result serving as the accumulator.\
156
179
---If an initial value is provided, it's used as the accumulator for index 1; otherwise, index 1 itself serves as the initial value, and iteration begins from index 2.
157
180
---@genericT
@@ -169,14 +192,43 @@ function lib.array:reduce(reducer, initialValue)
169
192
returnaccumulator
170
193
end
171
194
195
+
---Reverses the elements inside an array.
196
+
functionlib.array:reverse()
197
+
locali, j=1, #self
198
+
199
+
whilei<jdo
200
+
self[i], self[j] =self[j], self[i]
201
+
i+=1
202
+
j-=1
203
+
end
204
+
205
+
returnself
206
+
end
207
+
208
+
---Removes the first element from an array and returns the removed element.
209
+
functionlib.array:shift()
210
+
returntable.remove(self, 1)
211
+
end
212
+
213
+
---Creates a new array with reversed elements from the given array.
214
+
functionlib.array:toReversed()
215
+
localreversed=lib.array:new()
216
+
217
+
fori=#self, 1, -1do
218
+
reversed:push(self[i])
219
+
end
220
+
221
+
returnreversed
222
+
end
223
+
172
224
---Returns true if the given table is an instance of array or an array-like table.
173
225
---@paramtblArrayLike
174
226
---@returnboolean
175
227
functionlib.array.isArray(tbl)
176
-
ifnottype(tbl) =='table' thenreturnfalseend
177
-
178
228
localtableType=table.type(tbl)
179
229
230
+
ifnottableTypethenreturnfalseend
231
+
180
232
iftableType=='array' ortableType=='empty' orlib.array.instanceOf(tbl, lib.array) then
0 commit comments