Skip to content

Instantly share code, notes, and snippets.

@danielpchen
Last active October 6, 2016 07:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielpchen/1bef5000cfda98dbf6be to your computer and use it in GitHub Desktop.
Save danielpchen/1bef5000cfda98dbf6be to your computer and use it in GitHub Desktop.
Sass implode()
// @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