// Chunks $list into $size large lists // ------------------------------------------------------------------------------- // @documentation http://sassylists.com/documentation/#chunk // ------------------------------------------------------------------------------- // @example chunk(a b c d e, 2) => a b, c d, e // @example chunk(a b c d e, 3) => a b c, d e // ------------------------------------------------------------------------------- // @param $list [List] : list // @param $size [Number] : length of lists // ------------------------------------------------------------------------------- // @return [List] @function chunk($list, $size) { @if $size >= length($list) { @return $list; } $index: 1; $result: (); @for $i from 1 through ceil(length($list) / $size) { $tmp: (); @for $j from 1 through $size { @if $index <= length($list) { $is-orphan: length($list) % $size == 1 and $j == 1; $tmp: if($is-orphan, nth($list, $index), append($tmp, nth($list, $index))); } $index: $index + 1; } $result: append($result, $tmp); } @return $result; }