Start at the beginning of the list. For each item, compare it to the items before it. If you find an item that is smaller than the item before it, swap their positions. Keep doing this until all the items are in the correct order from smallest to largest.
ls = [1, 2, 3, 4, 3, 3, 3, 8, 9] for i in range(len(ls)): for j in range(i, 0, -1): if ls[j] < ls[j - 1]: ls[j], ls[j - 1] = ls[j - 1], ls[j] print(ls)
const list = [1, 2, 3, 4, 3, 3, 3, 8, 9]; for (let i = 0; i < list.length; i++) { for (let j = i; j > 0; j--) { if (list[j] < list[j - 1]) { [list[j], list[j - 1]] = [list[j - 1], list[j]]; } } } console.log(list);