-
-
Save allejo/68e500cbe6d92e4332b0 to your computer and use it in GitHub Desktop.
Reverse the order of a SASS map.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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