Last active
May 2, 2021 09:07
-
-
Save KDCinfo/3b4d345e76d8c7dd3f0f571bdefcdfdb to your computer and use it in GitHub Desktop.
Find differences between two Lists with Dart | Flutter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// | |
/// Find differences between two Lists with Dart | Flutter | |
/// | |
/// DartPad: https://dartpad.dev/3b4d345e76d8c7dd3f0f571bdefcdfdb | |
/// | |
void main() { | |
List<double> _current = [1, 2, 3, 4, 7]; // [1,2,3,4, 7] | |
List<double> _new = [3, 5, 6, 7, 9, 10]; // [ 3, 5,6,7,9,10] | |
List<double> output1 = | |
_current.where((element) => !_new.contains(element)).toList(); | |
print(output1 | |
.toString()); // [1, 2, 4] Existed in `_current` but are not in `_new`. | |
List<double> output2 = | |
_new.where((element) => !_current.contains(element)).toList(); | |
print(output2 | |
.toString()); // [5, 6, 9, 10] Were not in `_current` and are indeed `_new`. | |
} | |
/// | |
/// Thanks to the Answer and Question on Stack Overflow: | |
/// [A: Karim Elghamry](https://stackoverflow.com/a/57633481/638153) | |
/// [Q: Sheshank S.](https://stackoverflow.com/questions/57633439/get-difference-of-lists-flutter-dart) | |
/// |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment