在阵列pserved为了$ P $路口时做? [英] Is order preserved in arrays when intersection is done?
问题描述
当我做两个数组的交集,有没有保证所得到的顺序是根据第一个数组的顺序?
When I do an intersection of two arrays, is there any guarantee that the resulting order is based on the order of the first array?
例如,如果我有
a = [1,2,3]
b = [3,2,1]
能 A和b
收益 [3,2,1]
,而不是 [1,2,3]
(这是我所期望的)?
could a & b
return [3,2,1]
, instead of [1,2,3]
(which is what I'd expect)?
我找不到任何在任的RDoc的直接解决这一或Array镐头的文档。
I can't find anything directly addressing this in either RDoc's or the Pickaxe's documentation of Array.
RubySpec具有它一个规范创建以与阵列为了元素第一次遇到,但我应该承担YARV的Ruby将履行该规范?
RubySpec has a specification that it creates an array with elements in order they are first encountered, but should I assume YARV Ruby will honour that specification?
推荐答案
看起来是有保障的功能。他们在升级修订39415 上的RDoc描述。它在将来应该体现出来。
Looks like it is a guaranteed feature. They upgraded the RDoc description in revision 39415. It should be reflected sometime.
这篇关于在阵列pserved为了$ P $路口时做?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!