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.

1 Like