Skip to content

Instantly share code, notes, and snippets.

@tjmonsi
Created December 29, 2023 12:50
Show Gist options
  • Save tjmonsi/7e4bc385e0eaab458b678ee7a85de332 to your computer and use it in GitHub Desktop.
Save tjmonsi/7e4bc385e0eaab458b678ee7a85de332 to your computer and use it in GitHub Desktop.
Simple find_index function to find items in list of maps
// USAGE:
// import_code("path/to/findindex.src")
// list = [item, item, item]
// somefunction = function (item, value)
// return item.something == value
// end function
//
// index = find_index(list, value, @somefunction)
find_index = function (list, value, fn)
index = 0
for item in list
if fn(item, value) then return index
index = index + 1
end for
end function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment