problem determining uniqueness in array of arrays

J

James Byrne

I create an array of arrays, each inner array containing the mtime value
and fully qualified pathname of a file.

sources = [ [ mtime.to_i, "filename" ], [. . . ] ]

It happens that the same file is occasionally added twice or more. I
want to eliminate the duplicates. I thought that sources.uniq! would
work but I was surprised to discover that it returned nil indicating
that there were no duplicates found. I then tried sources.uniq.sort to
see if this was true and saw this:

1276181402
acrfile.0610104802

1276181402
acrfile.0610104802

1276181402
acrfile.0610104802

All elements of the outer array belong to class Array. The class of the
first element in each inner array is Fixnum, that of the second is
String.

So, what is it about Array#uniq that I misapprehend? Why do three
apparently identical inner arrays remain in the outer array after #uniq
is applied to it?
 
B

botp

So, what is it about Array#uniq that I misapprehend? =A0Why do three
apparently identical inner arrays remain in the outer array after #uniq
is applied to it?

pls show your code.

eg,

sources=3D[ [1276181402, "acrfile.0610104802"],
[1276181402, "acrfile.0610104802"],
[1276181402, "acrfile.0610104802"],
]
#=3D> [[1276181402, "acrfile.0610104802"], [1276181402,
"acrfile.0610104802"], [1276181402, "acrfile.0610104802"]]

p sources.uniq
[[1276181402, "acrfile.0610104802"]]
#=3D> [[1276181402, "acrfile.0610104802"]]

p sources.uniq.sort
[[1276181402, "acrfile.0610104802"]]
#=3D> [[1276181402, "acrfile.0610104802"]]

p sources.uniq!
[[1276181402, "acrfile.0610104802"]]
#=3D> [[1276181402, "acrfile.0610104802"]]

sources
#=3D> [[1276181402, "acrfile.0610104802"]]

best regards -botp
 
J

James Byrne

James Byrne wrote in post #979634:
So, what is it about Array#uniq that I misapprehend? Why do three
apparently identical inner arrays remain in the outer array after #uniq
is applied to it?

I discovered my error. The Pathname varied ever so slightly
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,150
Members
46,697
Latest member
AugustNabo

Latest Threads

Top