Created
December 29, 2023 12:50
-
-
Save tjmonsi/7e4bc385e0eaab458b678ee7a85de332 to your computer and use it in GitHub Desktop.
Simple find_index function to find items in list of maps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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