Sort list of paths

I would like to sort the following list:
paths := []string{a/b/c,a, b/x, a (2), bat, a/b, b}
I would like to obtain this result:
a (2)

Is this code Ok or can we sort it faster?

Any idea?

It looks good. The only complaint I have is that Idx should not have a capital I because this is reserved for exported function, types and vars.

You could do one thing which could speed it up. First split all paths and get a slice of slices of string and then do the sort and then concatenate them again. In this way would not strings.Split be called for every Less and it would go faster especially if slice is long.

One other way is to replace / with a character with a very low value and compare the strings after that. It would work. Like

1 Like

The replace hack is a the solution I was looking for. Thanks!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.