ListFunctions 0.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ListFunctions.rb +29 -29
- data/stylesheets/ListFunctions/_chunk.scss +32 -32
- data/stylesheets/ListFunctions/_count-values.scss +32 -32
- data/stylesheets/ListFunctions/_debug.scss +34 -34
- data/stylesheets/ListFunctions/_first.scss +12 -12
- data/stylesheets/ListFunctions/_insert-nth.scss +51 -51
- data/stylesheets/ListFunctions/_is-symmetrical.scss +22 -22
- data/stylesheets/ListFunctions/_last-index.scss +24 -24
- data/stylesheets/ListFunctions/_last.scss +12 -12
- data/stylesheets/ListFunctions/_loop.scss +20 -20
- data/stylesheets/ListFunctions/_prepend.scss +15 -15
- data/stylesheets/ListFunctions/_purge.scss +20 -20
- data/stylesheets/ListFunctions/_remove-duplicates.scss +29 -29
- data/stylesheets/ListFunctions/_remove-nth.scss +22 -22
- data/stylesheets/ListFunctions/_remove.scss +18 -18
- data/stylesheets/ListFunctions/_replace-nth.scss +49 -49
- data/stylesheets/ListFunctions/_replace.scss +31 -31
- data/stylesheets/ListFunctions/_reverse.scss +29 -29
- data/stylesheets/ListFunctions/_slice.scss +59 -59
- data/stylesheets/ListFunctions/_sort.scss +42 -0
- data/stylesheets/ListFunctions/_sum.scss +32 -32
- data/stylesheets/ListFunctions/_to-string.scss +28 -28
- data/stylesheets/_ListFunctions.scss +94 -90
- data/templates/project/sass/ListFunctions/_chunk.scss +32 -32
- data/templates/project/sass/ListFunctions/_count-values.scss +32 -32
- data/templates/project/sass/ListFunctions/_debug.scss +34 -34
- data/templates/project/sass/ListFunctions/_first.scss +12 -12
- data/templates/project/sass/ListFunctions/_insert-nth.scss +51 -51
- data/templates/project/sass/ListFunctions/_is-symmetrical.scss +22 -22
- data/templates/project/sass/ListFunctions/_last-index.scss +24 -24
- data/templates/project/sass/ListFunctions/_last.scss +12 -12
- data/templates/project/sass/ListFunctions/_loop.scss +20 -20
- data/templates/project/sass/ListFunctions/_prepend.scss +15 -15
- data/templates/project/sass/ListFunctions/_purge.scss +20 -20
- data/templates/project/sass/ListFunctions/_remove-duplicates.scss +29 -29
- data/templates/project/sass/ListFunctions/_remove-nth.scss +22 -22
- data/templates/project/sass/ListFunctions/_remove.scss +18 -18
- data/templates/project/sass/ListFunctions/_replace-nth.scss +49 -49
- data/templates/project/sass/ListFunctions/_replace.scss +31 -31
- data/templates/project/sass/ListFunctions/_reverse.scss +29 -29
- data/templates/project/sass/ListFunctions/_slice.scss +59 -59
- data/templates/project/sass/ListFunctions/_sum.scss +32 -32
- data/templates/project/sass/ListFunctions/_to-string.scss +28 -28
- data/templates/project/sass/_ListFunctions.scss +90 -90
- metadata +18 -11
- checksums.yaml +0 -7
data/lib/ListFunctions.rb
CHANGED
@@ -1,30 +1,30 @@
|
|
1
|
-
# All gems that are required for this extension to work should go here.
|
2
|
-
# These are the requires you would normally put in your config.rb file
|
3
|
-
# By default, you should always included Compass. Do not include your
|
4
|
-
# extension.
|
5
|
-
require 'compass'
|
6
|
-
|
7
|
-
# This tells Compass what your Compass extension is called, and where to find
|
8
|
-
# its files
|
9
|
-
# Replace 'ListFunctions' with the name of your extension. Spaces allowed.
|
10
|
-
extension_path = File.expand_path(File.join(File.dirname(__FILE__), ".."))
|
11
|
-
Compass::Frameworks.register('ListFunctions', :path => extension_path)
|
12
|
-
|
13
|
-
# Version and date of version for your Compass extension.
|
14
|
-
# Replace MyExtension with the name of your extension
|
15
|
-
# Letters, numbers, and underscores only
|
16
|
-
# Version is a number. If a version contains alphas, it will be created as
|
17
|
-
# a prerelease version
|
18
|
-
# Date is in the form of YYYY-MM-DD
|
19
|
-
module ListFunctions
|
20
|
-
VERSION = "0.
|
21
|
-
DATE = "2013-10-
|
22
|
-
end
|
23
|
-
|
24
|
-
# This is where any custom SassScript should be placed. The functions will be
|
25
|
-
# available on require of your extension without the need for users to import
|
26
|
-
# any partials. Uncomment below.
|
27
|
-
|
28
|
-
# module Sass::Script::Functions
|
29
|
-
#
|
1
|
+
# All gems that are required for this extension to work should go here.
|
2
|
+
# These are the requires you would normally put in your config.rb file
|
3
|
+
# By default, you should always included Compass. Do not include your
|
4
|
+
# extension.
|
5
|
+
require 'compass'
|
6
|
+
|
7
|
+
# This tells Compass what your Compass extension is called, and where to find
|
8
|
+
# its files
|
9
|
+
# Replace 'ListFunctions' with the name of your extension. Spaces allowed.
|
10
|
+
extension_path = File.expand_path(File.join(File.dirname(__FILE__), ".."))
|
11
|
+
Compass::Frameworks.register('ListFunctions', :path => extension_path)
|
12
|
+
|
13
|
+
# Version and date of version for your Compass extension.
|
14
|
+
# Replace MyExtension with the name of your extension
|
15
|
+
# Letters, numbers, and underscores only
|
16
|
+
# Version is a number. If a version contains alphas, it will be created as
|
17
|
+
# a prerelease version
|
18
|
+
# Date is in the form of YYYY-MM-DD
|
19
|
+
module ListFunctions
|
20
|
+
VERSION = "0.2"
|
21
|
+
DATE = "2013-10-16"
|
22
|
+
end
|
23
|
+
|
24
|
+
# This is where any custom SassScript should be placed. The functions will be
|
25
|
+
# available on require of your extension without the need for users to import
|
26
|
+
# any partials. Uncomment below.
|
27
|
+
|
28
|
+
# module Sass::Script::Functions
|
29
|
+
#
|
30
30
|
# end
|
@@ -1,32 +1,32 @@
|
|
1
|
-
/**
|
2
|
-
* Chunk $list into $size large lists
|
3
|
-
* -------------------------------------------------------------------------------
|
4
|
-
* @example chunk( (a, b, c, d, e), 2 ) => a b, c d, e
|
5
|
-
* @example chunk( (a, b, c, d, e), 3 ) => a b c, d e
|
6
|
-
* @example chunk( a, 3 ) => a
|
7
|
-
* -------------------------------------------------------------------------------
|
8
|
-
* @param $list [List] : list
|
9
|
-
* @param $size [Number] : length of lists
|
10
|
-
* -------------------------------------------------------------------------------
|
11
|
-
* @return [List]
|
12
|
-
*/
|
13
|
-
@function chunk($list, $size) {
|
14
|
-
$n: ceil(length($list) / $size);
|
15
|
-
$temp-index: 0;
|
16
|
-
$result: ();
|
17
|
-
|
18
|
-
@for $i from 1 through $n {
|
19
|
-
$temp-list: ();
|
20
|
-
|
21
|
-
@for $j from 1 + $temp-index through $size + $temp-index {
|
22
|
-
@if $j <= length($list) {
|
23
|
-
$temp-list: append($temp-list, nth($list, $j));
|
24
|
-
}
|
25
|
-
}
|
26
|
-
|
27
|
-
$result: append($result, $temp-list);
|
28
|
-
$temp-index: $temp-index + $size;
|
29
|
-
}
|
30
|
-
|
31
|
-
@return $result;
|
32
|
-
}
|
1
|
+
/**
|
2
|
+
* Chunk $list into $size large lists
|
3
|
+
* -------------------------------------------------------------------------------
|
4
|
+
* @example chunk( (a, b, c, d, e), 2 ) => a b, c d, e
|
5
|
+
* @example chunk( (a, b, c, d, e), 3 ) => a b c, d e
|
6
|
+
* @example chunk( a, 3 ) => a
|
7
|
+
* -------------------------------------------------------------------------------
|
8
|
+
* @param $list [List] : list
|
9
|
+
* @param $size [Number] : length of lists
|
10
|
+
* -------------------------------------------------------------------------------
|
11
|
+
* @return [List]
|
12
|
+
*/
|
13
|
+
@function chunk($list, $size) {
|
14
|
+
$n: ceil(length($list) / $size);
|
15
|
+
$temp-index: 0;
|
16
|
+
$result: ();
|
17
|
+
|
18
|
+
@for $i from 1 through $n {
|
19
|
+
$temp-list: ();
|
20
|
+
|
21
|
+
@for $j from 1 + $temp-index through $size + $temp-index {
|
22
|
+
@if $j <= length($list) {
|
23
|
+
$temp-list: append($temp-list, nth($list, $j));
|
24
|
+
}
|
25
|
+
}
|
26
|
+
|
27
|
+
$result: append($result, $temp-list);
|
28
|
+
$temp-index: $temp-index + $size;
|
29
|
+
}
|
30
|
+
|
31
|
+
@return $result;
|
32
|
+
}
|
@@ -1,33 +1,33 @@
|
|
1
|
-
/**
|
2
|
-
* Count the number of occurrences of each value of $list
|
3
|
-
* -------------------------------------------------------------------------------
|
4
|
-
* @dependence `replace-nth()`
|
5
|
-
* -------------------------------------------------------------------------------
|
6
|
-
* @example count-values( (a, b, c, d, e) ) => a 1, b 1, c 1, d 1, e 1
|
7
|
-
* @example count-values( (a, b, c, a, d, b, a, e) ) => a 3, b 2, c 1, d 1, e 1
|
8
|
-
* @example count-values( a ) => a 1
|
9
|
-
* -------------------------------------------------------------------------------
|
10
|
-
* @param $list [List] : list
|
11
|
-
* -------------------------------------------------------------------------------
|
12
|
-
* @return [List]
|
13
|
-
*/
|
14
|
-
@function count-values($list) {
|
15
|
-
$keys : ();
|
16
|
-
$counts : ();
|
17
|
-
|
18
|
-
@each $item in $list {
|
19
|
-
$index: index($keys, $item);
|
20
|
-
|
21
|
-
@if not $index {
|
22
|
-
$keys : append($keys, $item);
|
23
|
-
$counts : append($counts, 1);
|
24
|
-
}
|
25
|
-
|
26
|
-
@else {
|
27
|
-
$count : nth($counts, $index) + 1;
|
28
|
-
$counts : replace-nth($counts, $index, $count);
|
29
|
-
}
|
30
|
-
}
|
31
|
-
|
32
|
-
@return zip($keys, $counts);
|
1
|
+
/**
|
2
|
+
* Count the number of occurrences of each value of $list
|
3
|
+
* -------------------------------------------------------------------------------
|
4
|
+
* @dependence `replace-nth()`
|
5
|
+
* -------------------------------------------------------------------------------
|
6
|
+
* @example count-values( (a, b, c, d, e) ) => a 1, b 1, c 1, d 1, e 1
|
7
|
+
* @example count-values( (a, b, c, a, d, b, a, e) ) => a 3, b 2, c 1, d 1, e 1
|
8
|
+
* @example count-values( a ) => a 1
|
9
|
+
* -------------------------------------------------------------------------------
|
10
|
+
* @param $list [List] : list
|
11
|
+
* -------------------------------------------------------------------------------
|
12
|
+
* @return [List]
|
13
|
+
*/
|
14
|
+
@function count-values($list) {
|
15
|
+
$keys : ();
|
16
|
+
$counts : ();
|
17
|
+
|
18
|
+
@each $item in $list {
|
19
|
+
$index: index($keys, $item);
|
20
|
+
|
21
|
+
@if not $index {
|
22
|
+
$keys : append($keys, $item);
|
23
|
+
$counts : append($counts, 1);
|
24
|
+
}
|
25
|
+
|
26
|
+
@else {
|
27
|
+
$count : nth($counts, $index) + 1;
|
28
|
+
$counts : replace-nth($counts, $index, $count);
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
@return zip($keys, $counts);
|
33
33
|
}
|
@@ -1,34 +1,34 @@
|
|
1
|
-
/**
|
2
|
-
* Returns $list as a string
|
3
|
-
* -------------------------------------------------------------------------------
|
4
|
-
* @example debug( (a, b, c, d, e) ) => [ a, b, c, d, e ]
|
5
|
-
* @example debug( (a b (c d e) ) ) => [ a, b, [ c, d, e ] ]
|
6
|
-
* @example debug( a ) => [ a ]
|
7
|
-
* -------------------------------------------------------------------------------
|
8
|
-
* @param $list [List] : list
|
9
|
-
* -------------------------------------------------------------------------------
|
10
|
-
* @return [String]
|
11
|
-
*/
|
12
|
-
@function debug($list) {
|
13
|
-
$result: #{"[ "};
|
14
|
-
|
15
|
-
@each $item in $list {
|
16
|
-
|
17
|
-
@if length($item) > 1 {
|
18
|
-
$result: $result#{debug($item)};
|
19
|
-
}
|
20
|
-
|
21
|
-
@else {
|
22
|
-
$result: $result#{$item};
|
23
|
-
}
|
24
|
-
|
25
|
-
@if index($list, $item) != length($list) {
|
26
|
-
$result: $result#{", "};
|
27
|
-
}
|
28
|
-
|
29
|
-
}
|
30
|
-
|
31
|
-
$result: $result#{" ]"};
|
32
|
-
|
33
|
-
@return $result;
|
34
|
-
}
|
1
|
+
/**
|
2
|
+
* Returns $list as a string
|
3
|
+
* -------------------------------------------------------------------------------
|
4
|
+
* @example debug( (a, b, c, d, e) ) => [ a, b, c, d, e ]
|
5
|
+
* @example debug( (a b (c d e) ) ) => [ a, b, [ c, d, e ] ]
|
6
|
+
* @example debug( a ) => [ a ]
|
7
|
+
* -------------------------------------------------------------------------------
|
8
|
+
* @param $list [List] : list
|
9
|
+
* -------------------------------------------------------------------------------
|
10
|
+
* @return [String]
|
11
|
+
*/
|
12
|
+
@function debug($list) {
|
13
|
+
$result: #{"[ "};
|
14
|
+
|
15
|
+
@each $item in $list {
|
16
|
+
|
17
|
+
@if length($item) > 1 {
|
18
|
+
$result: $result#{debug($item)};
|
19
|
+
}
|
20
|
+
|
21
|
+
@else {
|
22
|
+
$result: $result#{$item};
|
23
|
+
}
|
24
|
+
|
25
|
+
@if index($list, $item) != length($list) {
|
26
|
+
$result: $result#{", "};
|
27
|
+
}
|
28
|
+
|
29
|
+
}
|
30
|
+
|
31
|
+
$result: $result#{" ]"};
|
32
|
+
|
33
|
+
@return quote($result);
|
34
|
+
}
|
@@ -1,13 +1,13 @@
|
|
1
|
-
/**
|
2
|
-
* Returns first element of $list
|
3
|
-
* -------------------------------------------------------------------------------
|
4
|
-
* @example first( (a, b, c) ) => a
|
5
|
-
* @example first( a ) => a
|
6
|
-
* -------------------------------------------------------------------------------
|
7
|
-
* @param $list [List] : list
|
8
|
-
* -------------------------------------------------------------------------------
|
9
|
-
* @return [Literal]
|
10
|
-
*/
|
11
|
-
@function first($list) {
|
12
|
-
@return nth($list, 1);
|
1
|
+
/**
|
2
|
+
* Returns first element of $list
|
3
|
+
* -------------------------------------------------------------------------------
|
4
|
+
* @example first( (a, b, c) ) => a
|
5
|
+
* @example first( a ) => a
|
6
|
+
* -------------------------------------------------------------------------------
|
7
|
+
* @param $list [List] : list
|
8
|
+
* -------------------------------------------------------------------------------
|
9
|
+
* @return [Literal]
|
10
|
+
*/
|
11
|
+
@function first($list) {
|
12
|
+
@return nth($list, 1);
|
13
13
|
}
|
@@ -1,52 +1,52 @@
|
|
1
|
-
/**
|
2
|
-
* Add $value at $index in $list
|
3
|
-
* -------------------------------------------------------------------------------
|
4
|
-
* @dependence `purge()`
|
5
|
-
* -------------------------------------------------------------------------------
|
6
|
-
* @example insert-nth( (a, b, c), 2, z ) => a, z, b, c
|
7
|
-
* @example insert-nth( (a, b, c), 0, z ) => error
|
8
|
-
* @example insert-nth( (a, b, c), -1, z ) => error
|
9
|
-
* @example insert-nth( (a, b, c), 10, z ) => error
|
10
|
-
* -------------------------------------------------------------------------------
|
11
|
-
* @param $list [List] : list
|
12
|
-
* @param $index [Number] : index to add
|
13
|
-
* @param $value [Literal] : value to add
|
14
|
-
* -------------------------------------------------------------------------------
|
15
|
-
* @raise [Error] if $index isn't an integer
|
16
|
-
* @raise [Error] if $index is strictly lesser than 1
|
17
|
-
* @raise [Error] if $index is strictly greater than length of $list
|
18
|
-
* -------------------------------------------------------------------------------
|
19
|
-
* @return [List] | false
|
20
|
-
*/
|
21
|
-
@function insert-nth($list, $index, $value) {
|
22
|
-
$result: false;
|
23
|
-
|
24
|
-
@if type-of($index) != number {
|
25
|
-
@warn "$index: #{quote($index)} is not a number for `insert-nth`.";
|
26
|
-
@return $result;
|
27
|
-
}
|
28
|
-
|
29
|
-
@else if $index < 1 {
|
30
|
-
@warn "List index 0 must be a non-zero integer for `insert-nth`";
|
31
|
-
@return $result;
|
32
|
-
}
|
33
|
-
|
34
|
-
@else if $index > length($list) {
|
35
|
-
@warn "List index is #{$index} but list is only #{length($list)} item long for `insert-nth'.";
|
36
|
-
@return $result;
|
37
|
-
}
|
38
|
-
|
39
|
-
@else {
|
40
|
-
$result: ();
|
41
|
-
|
42
|
-
@for $i from 1 through length($list) {
|
43
|
-
@if $i == $index {
|
44
|
-
$result: append($result, $value);
|
45
|
-
}
|
46
|
-
|
47
|
-
$result: append($result, nth($list, $i));
|
48
|
-
}
|
49
|
-
}
|
50
|
-
|
51
|
-
@return purge($result);
|
1
|
+
/**
|
2
|
+
* Add $value at $index in $list
|
3
|
+
* -------------------------------------------------------------------------------
|
4
|
+
* @dependence `purge()`
|
5
|
+
* -------------------------------------------------------------------------------
|
6
|
+
* @example insert-nth( (a, b, c), 2, z ) => a, z, b, c
|
7
|
+
* @example insert-nth( (a, b, c), 0, z ) => error
|
8
|
+
* @example insert-nth( (a, b, c), -1, z ) => error
|
9
|
+
* @example insert-nth( (a, b, c), 10, z ) => error
|
10
|
+
* -------------------------------------------------------------------------------
|
11
|
+
* @param $list [List] : list
|
12
|
+
* @param $index [Number] : index to add
|
13
|
+
* @param $value [Literal] : value to add
|
14
|
+
* -------------------------------------------------------------------------------
|
15
|
+
* @raise [Error] if $index isn't an integer
|
16
|
+
* @raise [Error] if $index is strictly lesser than 1
|
17
|
+
* @raise [Error] if $index is strictly greater than length of $list
|
18
|
+
* -------------------------------------------------------------------------------
|
19
|
+
* @return [List] | false
|
20
|
+
*/
|
21
|
+
@function insert-nth($list, $index, $value) {
|
22
|
+
$result: false;
|
23
|
+
|
24
|
+
@if type-of($index) != number {
|
25
|
+
@warn "$index: #{quote($index)} is not a number for `insert-nth`.";
|
26
|
+
@return $result;
|
27
|
+
}
|
28
|
+
|
29
|
+
@else if $index < 1 {
|
30
|
+
@warn "List index 0 must be a non-zero integer for `insert-nth`";
|
31
|
+
@return $result;
|
32
|
+
}
|
33
|
+
|
34
|
+
@else if $index > length($list) {
|
35
|
+
@warn "List index is #{$index} but list is only #{length($list)} item long for `insert-nth'.";
|
36
|
+
@return $result;
|
37
|
+
}
|
38
|
+
|
39
|
+
@else {
|
40
|
+
$result: ();
|
41
|
+
|
42
|
+
@for $i from 1 through length($list) {
|
43
|
+
@if $i == $index {
|
44
|
+
$result: append($result, $value);
|
45
|
+
}
|
46
|
+
|
47
|
+
$result: append($result, nth($list, $i));
|
48
|
+
}
|
49
|
+
}
|
50
|
+
|
51
|
+
@return purge($result);
|
52
52
|
}
|
@@ -1,23 +1,23 @@
|
|
1
|
-
/**
|
2
|
-
* Test if $list is symmetrical (one-level deep)
|
3
|
-
* -------------------------------------------------------------------------------
|
4
|
-
* @dependence `reverse()`
|
5
|
-
* -------------------------------------------------------------------------------
|
6
|
-
* @example is-symmetrical( (a, b, c, d, e) ) => false
|
7
|
-
* @example is-symmetrical( (a, b, c, b, a) ) => true
|
8
|
-
* @example is-symmetrical( a ) => true
|
9
|
-
* @example is-symmetrical( a, b c d, a ) => true
|
10
|
-
* -------------------------------------------------------------------------------
|
11
|
-
* @param $list [List] : list
|
12
|
-
* -------------------------------------------------------------------------------
|
13
|
-
* @return [Boolean]
|
14
|
-
*/
|
15
|
-
@function is-symmetrical($list) {
|
16
|
-
$result: ();
|
17
|
-
|
18
|
-
@each $item in $list {
|
19
|
-
$result: append($result, $item, space);
|
20
|
-
}
|
21
|
-
|
22
|
-
@return $result == reverse($result);
|
1
|
+
/**
|
2
|
+
* Test if $list is symmetrical (one-level deep)
|
3
|
+
* -------------------------------------------------------------------------------
|
4
|
+
* @dependence `reverse()`
|
5
|
+
* -------------------------------------------------------------------------------
|
6
|
+
* @example is-symmetrical( (a, b, c, d, e) ) => false
|
7
|
+
* @example is-symmetrical( (a, b, c, b, a) ) => true
|
8
|
+
* @example is-symmetrical( a ) => true
|
9
|
+
* @example is-symmetrical( a, b c d, a ) => true
|
10
|
+
* -------------------------------------------------------------------------------
|
11
|
+
* @param $list [List] : list
|
12
|
+
* -------------------------------------------------------------------------------
|
13
|
+
* @return [Boolean]
|
14
|
+
*/
|
15
|
+
@function is-symmetrical($list) {
|
16
|
+
$result: ();
|
17
|
+
|
18
|
+
@each $item in $list {
|
19
|
+
$result: append($result, $item, space);
|
20
|
+
}
|
21
|
+
|
22
|
+
@return $result == reverse($result);
|
23
23
|
}
|
@@ -1,24 +1,24 @@
|
|
1
|
-
/**
|
2
|
-
* Returns last index of $value in $list
|
3
|
-
* -------------------------------------------------------------------------------
|
4
|
-
* @example last-index( (a, b, c, a), a ) => 4
|
5
|
-
* @example last-index( (a, b, c), z ) => null
|
6
|
-
* -------------------------------------------------------------------------------
|
7
|
-
* @param $list [List] : list
|
8
|
-
* @param $value [Literal] : value to be searched for
|
9
|
-
* -------------------------------------------------------------------------------
|
10
|
-
* @return [Number] | null
|
11
|
-
*/
|
12
|
-
@function last-index($list, $value) {
|
13
|
-
|
14
|
-
@for $i from length($list) * -1 through -1 {
|
15
|
-
$i: abs($i);
|
16
|
-
|
17
|
-
@if nth($list, $i) == $value {
|
18
|
-
@return $i;
|
19
|
-
}
|
20
|
-
|
21
|
-
}
|
22
|
-
|
23
|
-
@return null;
|
24
|
-
}
|
1
|
+
/**
|
2
|
+
* Returns last index of $value in $list
|
3
|
+
* -------------------------------------------------------------------------------
|
4
|
+
* @example last-index( (a, b, c, a), a ) => 4
|
5
|
+
* @example last-index( (a, b, c), z ) => null
|
6
|
+
* -------------------------------------------------------------------------------
|
7
|
+
* @param $list [List] : list
|
8
|
+
* @param $value [Literal] : value to be searched for
|
9
|
+
* -------------------------------------------------------------------------------
|
10
|
+
* @return [Number] | null
|
11
|
+
*/
|
12
|
+
@function last-index($list, $value) {
|
13
|
+
|
14
|
+
@for $i from length($list) * -1 through -1 {
|
15
|
+
$i: abs($i);
|
16
|
+
|
17
|
+
@if nth($list, $i) == $value {
|
18
|
+
@return $i;
|
19
|
+
}
|
20
|
+
|
21
|
+
}
|
22
|
+
|
23
|
+
@return null;
|
24
|
+
}
|