Skip to content

Instantly share code, notes, and snippets.

@scottkellum
Last active November 25, 2015 12:49
Show Gist options
  • Save scottkellum/30e4863bd03ce0e1617c to your computer and use it in GitHub Desktop.
Save scottkellum/30e4863bd03ce0e1617c to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
// ----
// Sass (v3.4.14)
// Compass (v1.0.3)
// ----
// FAST but not fully featured sort
// Doesn’t support super high values or letters.
// Doesn’t work in LibSass as of November 25, 2015
// Take in multiple arguments as a list.
@function sort($l...) {
// Seed the return list
$return: ();
// Loop through the list only once.
@for $i from 0 to length($l) {
// Find the lowest value
$m: min($l...);
// Write that value to the return
$return: append($return,$m);
// Replace that value in the list so it won’t be called again.
$l: set-nth($l, index($l,$m), 9999999999);
}
// Return the newly sorted list
@return $return;
}
foo {
sorted: sort(40,3,23,455,234,1,-12,-14,23,4,-51,-29495,4929128,423);
}
foo {
sorted: -29495 -51 -14 -12 1 3 4 23 23 40 234 423 455 4929128;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment