list.insert-nth()
The insert-nth()
function returns the $list
with $value
inserted into index $n
.
// Sass.
@use 'sass:list';
// The `list.insert-nth()` function.
@function insert-nth($list, $n, $value) {
$result: ();
@for $i from 1 through list.length($list) {
@if $n == $i {
$result: list.append($result, $value, list.separator($list));
}
$result: list.append($result, list.nth($list, $i), list.separator($list));
}
@return $result;
}
https://github.com/angular-package/sass/blob/main/list/_list.insert-nth.function.scss
// Sass.
@use 'sass:list';
// Status: DONE
// The `list.insert-nth()` function returns the `$list` with `$value` inserted into index `$n`.
// @param `$list` The list to insert `$value` at index `$n`.
// @param `$n` The index `$n` under which `$value` is inserted.
// @param `$value` The value to insert at `$n` index.
// @return The return value is the list with the inserted `$value` at the `$n` index.
@function insert-nth($list, $n, $value) {
$result: ();
@for $i from 1 through list.length($list) {
@if $n == $i {
$result: list.append($result, $value, list.separator($list));
}
$result: list.append($result, list.nth($list, $i), list.separator($list));
}
@return $result;
}
// Examples.
// @debug insert-nth(('a', 'b', 'd', 'e', 'f', 'g'), 3 , 'c'); // "a", "b", "c", "d", "e", "f", "g"
// @debug insert-nth('a' 'b' 'd' 'e' 'f' 'g', 3, 'c'); // "a" "b" "c" "d" "e" "f" "g"
// @debug insert-nth(('a' 1) ('b' 2) ('d' 4) ('e' 5) ('f' 6) ('g' 7), 3, ('c' 3)); // ("a" 1) ("b" 2) ("c" 3) ("d" 4) ("e" 5) ("f" 6) ("g" 7)
Parameters
$list
$list
The list to insert $value
at index $n
.
$n
$n
The index $n
under which $value
is inserted.
$value
$value
The value to insert at the $n
index.
Return
The return value is the list with the inserted $value
at the $n
index.
Examples
// Use.
@use 'angular-package/sass/list';
// Examples.
@debug list.insert-nth(('a', 'b', 'd', 'e', 'f', 'g'), 3 , 'c'); // "a", "b", "c", "d", "e", "f", "g"
@debug list.insert-nth('a' 'b' 'd' 'e' 'f' 'g', 3, 'c'); // "a" "b" "c" "d" "e" "f" "g"
@debug list.insert-nth(('a' 1) ('b' 2) ('d' 4) ('e' 5) ('f' 6) ('g' 7), 3, ('c' 3)); // ("a" 1) ("b" 2) ("c" 3) ("d" 4) ("e" 5) ("f" 6) ("g" 7)
Last updated
Was this helpful?