def insertion_sort(array: list, ascending=True) -> list:
    """This function sort an array implementing the insertion sort method    

    Parameters
    ----------
    array : list
        A list containing the elements to be sorted
    ascending : boolen
        Indicates whether to sort in ascending order

    Returns
    -------
    list
        A sorted list
    """

    list_len = len(array)

    if list_len > 1:
        for i in range(1, list_len):
            for j in range(i, 0, -1):
                if ascending and array[j] < array[j - 1]:
                    array[j], array[j - 1] = array[j - 1], array[j]
                elif not ascending and array[j] > array[j - 1]:
                    array[j], array[j - 1] = array[j - 1], array[j]
                else:
                    break
    return array