Sort array by a number

Hi Guys

Is there a way to get the sort function to treat the key (which is a string) as a number?

It’s currently sorting it to 1, 11, 12, 2, 3, 4, etc.

I’ve gone ahead and changed the Monday column to text instead of number and changed them all to 01, 02, etc. But is there a cleaner option within Make that doesn’t involve iterating through the whole array and adding everything to a new array (could be expensive operations wise)?

image

Hi @CarlaK ,

With the available functions available with Make, the only way I think to sort an array of number in a string format is by iterating them and parse them as a number to sort them. As you mention it’s not really efficient and could cost a lot of operations.
Another way would be to use a custom module including a Javascript function to do the job.

I did develop that module for you , feel free to install it and test it.
Custom module installation


The blueprint if you want test it with a model :
sort string numbers.json (4.5 KB)

Please mark this post the solution if it works for you, thank you.

2 Likes

@Florian did you unpublish the custom module? I can’t seem to use it after installing.
Thank you!

Hello Andy, the module is still online and works, use that link to install it : https://www.make.com/en/hq/app-invitation/b444741427d9674df9de24f6e96ebdb2

1 Like

WORKAROUND:


I solved this by parsing the strings as numbers, then adding to a Number Array in Datastore. Then sorting the Array in Datastore in ASC or DES.

2 Likes

Hey there, I’m seeing this when trying to install:
image

When I install, I don’t see any modules in Make.

I’d love to use this if there’s a fix.

Andy