Sha256: c1d9333aac06d4113431273343a8cf44f9ac2dd1d9419751fe1cd3c1d82784fd

Contents?: true

Size: 1.19 KB

Versions: 15

Compression:

Stored size: 1.19 KB

Contents

//////////////////////////////
// Quicksort
// http://rosettacode.org/wiki/Sorting_algorithms/Quicksort
//////////////////////////////
@function quicksort($list) {

  $QS-Less: ();
  $QS-Equal: ();
  $QS-Large: ();

  $QS-Length: length($list);

  $QS-Seed: round($QS-Length / 2);

  @if $QS-Length > 1 {
    $QS-Seed: nth($list, $QS-Seed);
    @each $Item in $list {
      @if $Item < $QS-Seed {
        $QS-Less: append($QS-Less, $Item);
      }
      @else if $Item == $QS-Seed {
        $QS-Equal: append($QS-Equal, $Item);
      }
      @else {
        $QS-Large: append($QS-Large, $Item);
      }
    }
    $QS-Less: quicksort($QS-Less);
    $QS-Large: quicksort($QS-Large);

    $QS-Return: join($QS-Less, $QS-Equal);
    $QS-Return: join($QS-Return, $QS-Large);

    @return $QS-Return;
  }

  @return $list;
}

//////////////////////////////
// Sort Map function
//////////////////////////////
@function sort-map($map, $reverse: false) {
  $Sort-Map-Keys: quicksort(map-keys($map));
  $Sort-Map-Map: ();

  @if $reverse {
    $Sort-Map-Keys: reverse($Sort-Map-Keys);
  }

  @each $key in $Sort-Map-Keys {
    $Sort-Map-Map: map-merge($Sort-Map-Map, ($key: map-get($map, $key)));
  }

  @return $Sort-Map-Map;
}

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
singularitygs-1.8.0 stylesheets/singularitygs/helpers/_sort.scss
singularitygs-1.7.1 stylesheets/singularitygs/helpers/_sort.scss
singularitygs-1.7.0 stylesheets/singularitygs/helpers/_sort.scss
singularitygs-1.6.2 stylesheets/singularitygs/helpers/_sort.scss
singularitygs-1.6.1 stylesheets/singularitygs/helpers/_sort.scss
singularitygs-1.5.1 stylesheets/singularitygs/helpers/_sort.scss
singularitygs-1.5.0 stylesheets/singularitygs/helpers/_sort.scss
singularitygs-1.4.0 stylesheets/singularitygs/helpers/_sort.scss
singularitygs-1.3.0 stylesheets/singularitygs/helpers/_sort.scss
singularitygs-1.2.3 stylesheets/singularitygs/helpers/_sort.scss
singularitygs-1.2.1 stylesheets/singularitygs/helpers/_sort.scss
singularitygs-1.2.0 stylesheets/singularitygs/helpers/_sort.scss
singularitygs-1.2.0.rc.6 stylesheets/singularitygs/helpers/_sort.scss
singularitygs-1.2.0.rc.3 stylesheets/singularitygs/helpers/_sort.scss
singularitygs-1.2.0.rc.1 stylesheets/singularitygs/helpers/_sort.scss