range.down()

The math.range-down() or range.down() function returns the range of numbers where $from is higher than $to.

// Sass.
@use 'sass:list';

// Functions.
@use '../../meta/meta.of-type.function';

// The `math.range-down()` or `range.down()` function.
@function down($from, $to, $step: 1, $except: null, $separator: auto) {
  @if meta.of-type(number, $from, $to, $step) and $from > $to {
    $result: ();
    $number: $from;
    @if $step > 0 {
      $step: $step * -1;
    }
    @while $number >= $to {
      $result: if(
        not $except or ($except and not list.index($except, $number)),
        list.append($result, $number, $separator),
        $result
      );
      $number: $number + $step;
    }

    @return if(list.length($result) > 0, $result, null);
  }
  @return null;
}

Parameters

$from

The value of the number type indicates the beginning of the range.

$to

The value of number type indicates the end of the range.

$step: 1

The value of number type indicates each increment of the range. By default, it's 1.

$except: null

The value of a number or list of numbers not belonging to the range.

$separator: auto

A separator between the given range numbers.

Return

The return value is the list of numbers of the given range.

Examples

// Use.
@use '@angular-package/sass/math';
@use '@angular-package/sass/math/range';

// Examples.
@debug math.range-down(20, 15); // 20 19 18 17 16 15

// step 0.1
@debug math.range-down(0.1, 1, 0.1); // 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

// step 2
@debug math.range-down(15, -3, 2); // 15 13 11 9 7 5 3 1 -1 -3

// except
@debug math.range-down(35, 20, 1, 20 35); // 34 33 32 31 30 29 28 27 26 25 24 23 22 21

// separator
@debug math.range-down(25, 20, $separator: comma); // 25, 24, 23, 22, 21, 20

// null
@debug math.range-down(20, 35); // null

Last updated