Sort a list of numbers easily without an extension

Doing a project I needed to sort a list of numbers. But I didn’t find a very simple way explained in the community, so I came up with this way to sort a list easily. I hope it works for you <3

First we need a list to sort (input_list)
imagen_2022-07-17_180038823

And then we start the ordered list with the first value of the unordered list:
image

Then we use a “for each” block to check each number of the unordered list starting at 2 because we already added the first value to the ordered list and ending at length of the list “unordered_list”
imagen_2022-07-17_180522859

And inside we use another “for each” block that starts at 1 to check the first position of the ordered list and ends at (length of the list “ordered_list” + 1):
imagen_2022-07-17_181306456

Then we will check if we are still within the size of the ordered list to check if the number is greater or less, and if we already passed the size of the ordered list then it is greater or less depending on what we want and we will add it to the end of the list subsequently:
image

So if we still haven’t exceeded the size of the ordered list then we will check if the element of the ordered list we are in is bigger or smaller (depending on what we want) and if it is then we insert it in its position and the number it was there it will move to the next place in the ordered list, and finally we finish the loop of the ordered list so as not to add extra numbers:

So at the end we replace the original list with the sorted list for whatever is needed
imagen_2022-07-17_182605715

7 Likes