-
-
Save milovtim/d7be812d0a2a18f8417794b9e70bb01e to your computer and use it in GitHub Desktop.
Lua table.filter (JavaScript Array::filter equivalent)
This file contains 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
-- table.filter({"a", "b", "c", "d"}, function(o, k, i) return o >= "c" end) --> {"c","d"} | |
-- | |
-- @FGRibreau - Francois-Guillaume Ribreau | |
-- @Redsmin - A full-feature client for Redis http://redsmin.com | |
table.filter = function(t, filterIter) | |
local out = {} | |
for k, v in pairs(t) do | |
if filterIter(v, k, t) then out[k] = v end | |
end | |
return out | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment