Skip to content

Instantly share code, notes, and snippets.

@seanislegend
Created November 19, 2014 14:00
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save seanislegend/107ccf9c81ec9fd1aae0 to your computer and use it in GitHub Desktop.
Save seanislegend/107ccf9c81ec9fd1aae0 to your computer and use it in GitHub Desktop.
Reverse the order of a SASS map.
@function mapReverse ($map) {
$result: null;
@if type-of($map) == "map" {
$keys: map-keys($map);
$map-reversed: ();
@for $i from length($keys) through 1 {
$map-reversed: map-merge(
$map-reversed,
(nth($keys, $i): map-get($map, nth($keys, $i)))
);
}
@if type-of($map-reversed) == "map" {
$result: $map-reversed;
} @else {
@warn 'There was an error reversing the order of "#{$map}"';
}
} @else {
@warn '"#{$map}" is not a valid map';
}
@return $result;
}
@thefotolander
Copy link

Works beautifully. Thanks! 👍

@rafegoldberg
Copy link

works like a charm – much appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment