Skip to content

Commit b31f804

Browse files
authored
feat(modules/lib): qbx.array.contains to check if an array contains a given value
1 parent f804a7e commit b31f804

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

modules/lib.lua

+16
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ local qbx = {}
44
qbx.string = {}
55
qbx.math = {}
66
qbx.table = {}
7+
qbx.array = {}
78

89
qbx.armsWithoutGloves = lib.table.freeze({
910
male = lib.table.freeze({
@@ -147,6 +148,21 @@ function qbx.table.mapBySubfield(tble, subfield)
147148
return map
148149
end
149150

151+
---Returns true if the given array contains the given value.
152+
---@generic T
153+
---@param arr T[]
154+
---@param val T
155+
---@return boolean
156+
function qbx.array.contains(arr, val)
157+
for i = 1, #arr do
158+
if arr[i] == val then
159+
return true
160+
end
161+
end
162+
163+
return false
164+
end
165+
150166
---Returns the number plate of the given vehicle.
151167
---@param vehicle integer
152168
---@return string?

0 commit comments

Comments
 (0)