Skip to content

Instantly share code, notes, and snippets.

@allejo
Forked from seanislegend/map-reverse.scss
Created November 17, 2015 07:28
Show Gist options
  • Save allejo/68e500cbe6d92e4332b0 to your computer and use it in GitHub Desktop.
Save allejo/68e500cbe6d92e4332b0 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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment