rhu_uw
Last Updated: February 25, 2016
·
503
· maikel22

Sass str-reverse function

You want to reverse a string in your sass, scss? Here you go:

Sass:

@function str-reverse($string)
  $reverse-string: ""
  @for $i from 1 through str-length($string)
    $c: str-slice($string, $i, $i)
    $reverse-string: "#{$c}#{$reverse-string}"
  @return $reverse-string

Scss:

@function str-reverse($string) {
    $reverse-string: "";
    @for $i from 1 through str-length($string) {
        $c: str-slice($string, $i, $i);
        $reverse-string: "#{$c}#{$reverse-string}";
    }
    @return $reverse-string;
  }