Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't sort when normalize would produce arrays of different length #21

Open
jeropaul opened this issue Jul 8, 2015 · 3 comments
Open

Comments

@jeropaul
Copy link

jeropaul commented Jul 8, 2015

Works well with structured data that is similar, but the following arbitrary strings cause a failure:

For example
arr = [ "99-101 some street address", "Some other thing", "1"]
Naturally.sort(arr)

results in ArgumentError: comparison of Array with Array failed, In this case ruby doesn't consider the arrays produced by Naturally.normalize to comparable.

@dogweather
Copy link
Owner

I can imagine that it fails. The thing is, though, what would the sort
order be for those strings?

On Tue, Jul 7, 2015 at 11:45 PM, Jerome [email protected] wrote:

Works well with structured data that is similar, but the following
arbitrary strings cause a failure:

For example
arr = [ "99-101 some street address", "Some other thing", "1"]
Naturally.sort(arr)

results in ArgumentError: comparison of Array with Array failed, In this
case ruby doesn't consider the arrays produced by Naturally.normalize to
comparable.


Reply to this email directly or view it on GitHub
#21.

@jeropaul
Copy link
Author

I don't have a solid opinion in regards to what I would expect. At a pinch I'd be happy with:

  • "1", "99-101 some street address", "Some other thing"

but I'm assuming numbers before letters and I can see others having (valid) opinions that it should be the other way around. The main point is that it shouldn't stack trace out when sorting strings regardless of whether the normalize method tokenizes the strings differently.

@dogweather
Copy link
Owner

The main point is that it shouldn't stack trace out...

Ah hah, I agree with you there. I think better behavior would be for #sort to raise a more meaningful "Can't sort this" exception. And then we could have a new method like #sort_always which would never raise an exception. Instead it'd do a simple Array#sort.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants