我想单线程返回true/false,它测试数组中的每个元素是否为整数。所以如果数组中的任何元素不是整数,它应该返回false,否则返回true。这里是我的尝试:Ruby - 测试每个数组元素,得到一个结果
>> ([2,1,4].map {|x| (x.is_a? Integer)}).reduce {|x, result| x and result}
=> true
>> ([2,"a",4].map {|x| (x.is_a? Integer)}).reduce {|x, result| x and result}
=> false
任何其他想法进一步提炼它?
完美,谢谢了。 – oaklodge 2010-10-05 17:45:48
感觉像魔术! – mko 2014-06-12 02:33:42