D
daniel åkerud
[Note: parts of this message were removed to make it a legal post.]
Please explain why "a" is corrupted after call to Array#sort:
irb(main):044:0> a=[[1, "abc"],[3, "def"],[2, "efg"]]
=> [[1, "abc"], [3, "def"], [2, "efg"]]
irb(main):045:0> a.sort { |a, b| a[0] <=> b[0] }
=> [[1, "abc"], [2, "efg"], [3, "def"]]
irb(main):046:0> a
=> [1, "abc"]
A new sorted array is correctly returned, but "a" itself is not left intact.
It seems to have something to do with me using an array-of-arrays.
/D
Please explain why "a" is corrupted after call to Array#sort:
irb(main):044:0> a=[[1, "abc"],[3, "def"],[2, "efg"]]
=> [[1, "abc"], [3, "def"], [2, "efg"]]
irb(main):045:0> a.sort { |a, b| a[0] <=> b[0] }
=> [[1, "abc"], [2, "efg"], [3, "def"]]
irb(main):046:0> a
=> [1, "abc"]
A new sorted array is correctly returned, but "a" itself is not left intact.
It seems to have something to do with me using an array-of-arrays.
/D