Created
April 13, 2015 22:25
-
-
Save mohsin/a1626b51603dd7a529b7 to your computer and use it in GitHub Desktop.
Sass version of PHP 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
// | |
// Returns string after joining list elements with a glue string. | |
// Similar to PHP's implode function | |
// | |
@function implode($list, $glue: '', $is-nested: false) | |
$result: null | |
@for $i from 1 through length($list) | |
$e: nth($list, $i) | |
@if type-of($e) == list | |
$result: $result#{to-string($e, $glue, true)} | |
@else | |
$result: if($i != length($list) or $is-nested, $result#{$e}#{$glue}, $result#{$e}) | |
@return $result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment