-
Notifications
You must be signed in to change notification settings - Fork 0
/
_uniq.scss
38 lines (33 loc) · 884 Bytes
/
_uniq.scss
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
@use './internal/is';
@import 'reduce';
///
/// Returns a new list containing only one copy of each element in the original
/// list.
///
/// @group list
/// @param {Array} list The array to consider.
/// @return {Array} The list of unique items.
/// @example scss - uniq
///
/// uniq([1, 1, 2, 1]); //=> [1, 2]
/// uniq([1, '1']); //=> [1, '1']
/// uniq([[42], [42]]); //=> [[42]]
///
@function uniq($list...) {
$result: ();
@if is.arglist($list) and length(nth($list, 1)) == 0 {
@return $result;
}
$_list: if(
is.arglist($list) and length($list) == 1,
reduce(append, (), nth($list, 1)),
$list
);
@each $item in $_list {
// should probably test with `get-function` for functions.
@if not index($result, $item) {
$result: append($result, $item);
}
}
@return $result;
}