Comparison

util/array.lua @ 4439:1c8d2c0d02db

util.array: Add pluck() method to pick a given property from each item
author Matthew Wild <mwild1@gmail.com>
date Wed, 07 Dec 2011 05:04:55 +0000
parent 4387:06161b0b83f2
child 4440:c60ed6732b34
comparison
equal deleted inserted replaced
4438:7f51186ed28b 4439:1c8d2c0d02db
55 function array_base.sort(outa, ina, ...) 55 function array_base.sort(outa, ina, ...)
56 if ina ~= outa then 56 if ina ~= outa then
57 outa:append(ina); 57 outa:append(ina);
58 end 58 end
59 t_sort(outa, ...); 59 t_sort(outa, ...);
60 return outa;
61 end
62
63 function array_base.pluck(outa, ina, key)
64 for i=1,#ina do
65 outa[i] = ina[i][key];
66 end
60 return outa; 67 return outa;
61 end 68 end
62 69
63 --- These methods only mutate 70 --- These methods only mutate
64 function array_methods:random() 71 function array_methods:random()