Search
 
SCRIPT & CODE EXAMPLE
 

DART

extract common elements from lists dart

// you can use fold and set

main() {
  final lists = [
    [1, 2, 3, 55, 7, 99, 21],
    [1, 4, 7, 65, 99, 20, 21],
    [0, 2, 6, 7, 21, 99, 26]
  ];

  final commonElements =
      lists.fold<Set>(
        lists.first.toSet(), 
        (a, b) => a.intersection(b.toSet()));

  print(commonElements);
}

// gives {7, 99, 21}
Comment

PREVIOUS NEXT
Code Example
Dart :: dartlang console plugin 
Dart :: dart multi line print statement 
Dart :: dart is operator 
Dart :: how to show snackbar in initState() in flutter 
Dart :: dart class with 
Dart :: how to craete function in flutter 
Dart :: flutter image size percentage 
Dart :: what is the problem to aqueduct with dart 2.8 
Swift :: settimeout in swift 
Swift :: swift check if string contains string 
Swift :: swift continue 
Swift :: swift create label programmatically 
Swift :: how to disable uitableview selection in swift 
Swift :: get hours difference between two dates swift 
Swift :: detect binding valu change swiftui 
Swift :: ShareSheet: UIViewControllerRepresentable swiftui 
Swift :: swift swipe gesture 
Swift :: swiftui play mp3 
Swift :: swift create array from range 
Swift :: costume font size swift ui 
Swift :: swift enum 
Swift :: convert string to unit swift 
Swift :: swift date to string 
Swift :: enviroment dissmiss swiftui 
Swift :: how to change background color of stackview swift 
Swift :: swift create an empty array 
Swift :: accessing tab bar item action swift 
Swift :: swiftui datepicker text color 
Swift :: ios get notification payload 
Swift :: Swift Named Associated Values 
ADD CONTENT
Topic
Content
Source link
Name
7+7 =