Jump to content
Tova

Sorting an array of objects by name

Recommended Posts

Hello !

 

I have an array of objects in the format :

[obj_10,obj_1,obj_12,obj_13,obj_14,obj_11,obj_2,obj_3,obj_4,obj_5,obj_6,obj_7,obj_8,obj_9]

I would like to sort this array so it becomes :

[obj_1,obj_2,obj_3,obj_4,obj_5,obj_6,obj_7,obj_8,obj_9,obj_10,obj_11,obj_12,obj_13,obj_14]

Also please note that the array contains objects and not strings !

 

I tried the sort function on the array, but no luck 😕

I believe the problem arises from alphabetical sorting as obj_11 comes before obj_2.

 

Any ideas on how to get around the issue ?

Thanks for the help !

Share this post


Link to post
Share on other sites
_sorted= [_yourArray, [], {(str _x splitString "_")select 1}, "ASCEND"] call BIS_fnc_sortBy;

try this (untested

  • Like 1

Share this post


Link to post
Share on other sites

Smart move !

 

It didn't work as it is, but you just forgot to add a ParseNumber since the third parameter of sortBy has to return a number 🙂

_sorted= [_yourArray, [], {parseNumber ((str _x splitString "_") select 1)}, "ASCEND"] call BIS_fnc_sortBy; 

Thanks a lot !

Share this post


Link to post
Share on other sites
Just now, Tova said:

It didn't work as is, you just forgot to add a ParseNumber

ah s*** I was meaning to...

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×