/// Insertion sort
/// @author Hugo Giraudel
/// @param {List} $list - list to sort
/// @param {List} $order ($default-order) - order to use for sorting
/// @return {List}
/// @require {function} _str-compare
@function insertion-sort($list, $order: $default-order) {
  @for $i from 1 through length($list) {
    $current: nth($list, $i);
    $j: $i - 1;

    @while $j > 0 and not _str-compare(nth($list, $j), $current, $order) {
      $list: set-nth($list, $j + 1, nth($list, $j));
      $j: $j - 1;
    }

    $list: set-nth($list, $j + 1, $current);
  }

  @return $list;
}
