/// Bubble 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 bubble-sort($list, $order: $default-order) {
  @for $i from 1 through length($list) {
    @for $j from $i through 1 {
      @if $j > 1 and _str-compare(nth($list, $j), nth($list, $j - 1), $order) {
        $list: _swap($list, $j, $j - 1);
      }
    }
  }

  @return $list;
}
