Performance: Built-in list functions
Using built-in list functions affects the CSS preprocessing speed and the size of the generated CSS, impacting initial page load and style application.
$my-list: 1 2 3 4 5; $len: length($my-list);
@function manual-list-length($list) { $length: 0; @each $item in $list { $length: $length + 1; } @return $length; } $my-list: 1 2 3 4 5; $len: manual-list-length($my-list);
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Manual list iteration in Sass | 0 (preprocessing only) | 0 | 0 | [OK] |
| Using built-in list functions (e.g., length()) | 0 (preprocessing only) | 0 | 0 | [OK] Good |
length() do when used on a list?length()length() function counts how many items are inside a list.nth() get an item, append() adds items, and join() combines lists, so they do different things.length() = count items [OK]$colors in Sass?nth() is used to get the item at a specific position in a list.nth($list, index). Other options like get() or bracket notation are invalid in Sass.$list1: 10px 20px 30px; $list2: 40px 50px; $result: join($list1, $list2);
What is the value of $result?
join() function combines two lists into one list separated by a comma by default.$list1 and $list2 results in a list: 10px 20px 30px, 40px 50px (comma-separated).$my-list: 1 2 3; $new-list: append($my-list, 4, comma);
append() must be a string: either 'space' or 'comma'.comma without quotes, which is invalid syntax in Sass.$listA: red green blue; $listB: yellow orange;
You want to create a new list that contains all items from $listA followed by $listB, separated by spaces, and then add black at the end. Which Sass code correctly does this?
join($listA, $listB, 'space') to combine both lists with spaces.append(..., black, 'space') to add 'black' at the end, keeping space separation.$combined: join(append($listA, black, 'space'), $listB, 'comma'); uses comma separator incorrectly; $combined: append($listA, join($listB, black, 'space'), 'space'); nests join inside append wrongly; $combined: join($listA, $listB, 'space') append(black); syntax is invalid.Pass the test and this pattern moves unknown