Created
November 25, 2024 02:06
-
-
Save Yannx79/fc2c6102480dab48fbcc6a32fe574f60 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is Pseudocode | |
function adjustOrder(list): | |
// Step 1: Adjust invalid values | |
for each element in list: | |
if element.order <= 0: | |
element.order = null // Mark as "no order" | |
// Step 2: Sort the list by 'order', moving null to the end | |
sort list by: | |
if a.order is null then return 1 | |
if b.order is null then return -1 | |
return a.order - b.order | |
// Step 3: Assign consecutive values to the 'order' field | |
currentOrder = 1 | |
for each element in list: | |
element.order = currentOrder | |
currentOrder = currentOrder + 1 | |
return list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment