I am trying to create a list which is calculated from another list. For example, if I have a list like 1,2,3,4... then the output has to be 10,20,30,40... Is there any other way to create a list from another in less? Please refer the below codes.
@input: 1,2,3,4;
.for(@array) when (default()) {.for-impl_(length(@array))}
.for-impl_(@i) when (@i > 1) {.for-impl_((@i - 1))}
.for-impl_(@i) when (@i > 0) {.-each(extract(@array, @i), @i)}
.create-list(@input){
.for(@input); .-each(@value, @a) {
.output_@{a}(@a) { // Create dynamic mixin based on input list
@output_@{a}: @a * 10; // Create dynamic variable to store each calc
}
}
}
.create-list(@input);
.loop(@count) when (@count > 0){
@prev: @count - 1;
.loop(@prev);
.first() when (@count = 1){
.output_@{count}(); // call first mixin which created already
@res_@{count}: @output_@{count} // Store the result in another dynamic var
}
.first() when not (@count = 1){
.output_@{count}();
@res_@{count}: @res_@{prev}, @output_@{count}; // join prev and current result
}
.first();
}
.loop(4);
The above implementation similar I expect like below.
.a1(){
@o1: #fff;
}
.a2(){
@o2: #aaa;
}
.a3(){
@o3: #ccc;
}
.loop(@counter) when (@counter > 0) {
.loop((@counter - 1));
.a1();
@out1: @o1;
.a2();
@out2: @out1, @o2;
.a3();
@out: @out2, @o3;
div{
colors: @out;
}
}
.loop(1);
and the output is #fff, #aaa, #ccc.