Comparison

util/array.lua @ 8017:ec7cab8e744d

util.array: Add method for filtering out duplicate values
author Kim Alvefur <zash@zash.se>
date Fri, 31 Mar 2017 17:29:08 +0200
parent 7976:2a7ef5fcaa77
child 8521:6f5ce0f09f40
comparison
equal deleted inserted replaced
8016:9546c629289b 8017:ec7cab8e744d
90 end 90 end
91 t_sort(outa, ...); 91 t_sort(outa, ...);
92 return outa; 92 return outa;
93 end 93 end
94 94
95 function array_base.unique(outa, ina)
96 local seen = {};
97 return array_base.filter(outa, ina, function (item)
98 if seen[item] then
99 return false;
100 else
101 seen[item] = true;
102 return true;
103 end
104 end);
105 end
106
95 function array_base.pluck(outa, ina, key) 107 function array_base.pluck(outa, ina, key)
96 for i = 1, #ina do 108 for i = 1, #ina do
97 outa[i] = ina[i][key]; 109 outa[i] = ina[i][key];
98 end 110 end
99 return outa; 111 return outa;