如果已经存在,则手写笔不按(网格循环)

Stylus dont push if already exsists (Grid Loop)

我正在尝试将以下内容从 SCSS 重写为 Stylus:

link to original SCSS codepen grid loop

// Total columns for layout
$total-columns: 6;
$col-widths: ();
@for $i from 1 through $total-columns {
    @for $j from 1 through $i {
        $w: ($j/$i);

        // If the width doesn't already exist
        @if not index($col-widths, $w) {
            .col-#{$j}-#{$i} {
                width: $w * 100%;
            }
            // Add the width to the array
            $col-widths: append($col-widths, $w, comma);
        }
    }
}

然而我坚持的部分是

@if not index($col-widths, $w)

如果 class w 已经存在,我不知道如何检查 col-widths 数组,因此不再添加它。

这是我目前得到的结果,但没有用。我错过了什么?

total-columns = 6
col-widths = ()

 for i in 1..total-columns 
   for j in 1..i 

     w = (j/i)

     if index in col-widths is not w
       .width{j}of{i} 
         lost-column: w
     else
       push(col-widths, w)

你可以在这里使用in操作符(实际上,你的代码几乎是正确的)。

total-columns = 6
col-widths = ()

for i in 1..total-columns 
   for j in 1..i 

     w = (j/i)

     unless w in col-widths
       .width{j}of{i} 
         lost-column: w
       push(col-widths, w)