Created
November 19, 2014 14:00
-
-
Save seanislegend/107ccf9c81ec9fd1aae0 to your computer and use it in GitHub Desktop.
Reverse the order of a SASS map.
This file contains hidden or 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; | |
} |
works like a charm – much appreciated!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works beautifully. Thanks! 👍