Last active
October 6, 2016 07:07
-
-
Save danielpchen/1bef5000cfda98dbf6be to your computer and use it in GitHub Desktop.
Sass implode()
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 implode() -- join list elements to form a single string | |
// {string} $pieces: the list of strings to implode | |
// {string} $glue: the "glue" between elements in the result string | |
// @return {string} the result string | |
@function implode($pieces, $glue: "") { | |
$result: null; | |
@for $i from 1 through length($pieces) { | |
$piece: nth($pieces, $i); | |
@if type-of($piece) == list { | |
$result: unquote("#{$result}#{$glue}#{implode($piece, $glue)}"); | |
} @else { | |
$result: unquote("#{$result}#{$glue}#{$piece}"); | |
} | |
} | |
@if $result != null { | |
$result: str-slice($result, str-length($glue) + 1, -1); | |
} | |
@return $result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment