List<String> checkLength(List<String> input) {
if (input.length > 6) {
var tempOutput = input;
while (tempOutput.length > 6) {
var difference = (tempOutput.length/6).round() + 1;
for (int i = 0; i < tempOutput.length - 1; i + difference) {
tempOutput.removeAt(i); //Removing the value from the list
}
}
return tempOutput; //Return Updated list
} else {
return input;
}
}
I am trying to delete something out of a temporary list. Why does it not work? I do not see how it is fixed, in other problems I have solved, I used a similar approach and it worked (Even identical nearly)
Please note I am kind of new to Dart, so please forgive me this sort of question, but I couldn't figure out the solution.
Find the Code available in the Dart Link
Code in Dart
If you want to increase it then you can do this num. addAll([1,1,1,1,1,1,1]) or num. addAll(List<int>. generate(20, (i) => 0)) .
As stated in the comments, you need to create each list separately and add them to them list of lists. The default growable list, as returned by new List() or [], keeps an internal buffer, and grows that buffer when necessary.
You can ensure that tempOutput
is not a fixed-length list by initializing it as
var tempOutput = new List<String>.from(input);
thereby declaring tempOutput
to be a mutable copy of input
.
FYI it also looks like you have another bug in your program since you are doing i + difference
in your for-loop update step but I think you want i += difference
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With