javascriptflutterdartradix-sort

Dart radix sort implementation


how can i write the below code in dart

// js code

let digitBuckets = Array.from({length: 10}, () => []);

// dart code

List digitBuckets = List.from({});//confused here

// how can i write this: Array.from({length: 10}, () => []);
// in dart List digitBuckets = ??

Solution

  • I am a little confused about what you want but I think you want to create a List of Lists which you can do like this:

    void main() {
      final digitBuckets = List.generate(10, (_) => <dynamic>[]);
      print(digitBuckets); // [[], [], [], [], [], [], [], [], [], []]
    }
    

    Note, the lists should be more specifically typed so you can get some type safety. But your questions does not contain any clue about what you want to use these lists for so I have used dynamic in my example.