Check out example codes for "create and return a merged list of all the elements in sorted order". It will help you in understanding the concepts better.

Code Example 1

result = []
while list1 and list2:
    result.append((list1 if list1[-1] > list2[-1] else list2).pop(-1))

if len(list1):
    result += list1[-1::-1]
if len(list2):
    result += list2[-1::-1]

return result[-1::-1]

Learn ReactJs, React Native from