Diff

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
line wrap: on
line diff
--- a/util/array.lua	Wed Dec 07 04:57:51 2011 +0000
+++ b/util/array.lua	Wed Dec 07 05:04:55 2011 +0000
@@ -60,6 +60,13 @@
 	return outa;
 end
 
+function array_base.pluck(outa, ina, key)
+	for i=1,#ina do
+		outa[i] = ina[i][key];
+	end
+	return outa;
+end
+
 --- These methods only mutate
 function array_methods:random()
 	return self[math.random(1,#self)];