Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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