/// Selection 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
/// @require {function} _swap
@function selection-sort($list, $order: $default-order) {
  @for $i from 1 through length($list) {
    $idx: $i;
    $min: nth($list, $i);

    @for $j from $i + 1 through length($list) {
      @if not _str-compare($min, nth($list, $j), $order) {
        $min: nth($list, $j);
        $idx: $j;
      }
    }

    $list: _swap($list, $i, $idx);
  }

  @return $list;
}
