Using Dart, what is a good way of iterating through a list of strings in search for a specific one, when string is found move it to the front of the list?
For example, if looking for the letter 'b'. Find it, move it up front.
['a', 'b', 'c']
=> ['b', 'a', 'c']
Not knowing Dart very well, I solved it with simple for-loop
List<String> example = ['a', 'b', 'c'];
for (int i = 0; i< example.length; i++) {
if (example[i] == 'b') {
final temp = example[0];
example[0] = example[i];
example[i] = temp;
}
}
Is there a way in dart to call some array method on a list to find a specific item, remove it from the original list and return the removed item? Like .splice() in JS.