Skip to content

Instantly share code, notes, and snippets.

@matifdeveloper
Created October 16, 2023 04:22
Show Gist options
  • Save matifdeveloper/278c688fe668b3c0fa0667d6f0ae604a to your computer and use it in GitHub Desktop.
Save matifdeveloper/278c688fe668b3c0fa0667d6f0ae604a to your computer and use it in GitHub Desktop.
Remove common values from two Lists

Remove common values from two Lists

Created with <3 with dartpad.dev.

void main() {
List a = [1,2,3,4,5];
List b = [6,7,8,9,1];
Map<int, int> commonData = {};
int maxLength = a.length > b.length ? a.length : b.length;
int minLength = a.length < b.length ? a.length : b.length;
for (int i = 0; i < maxLength; i++) {
commonData[a[i]] = a[i];
if(i < minLength){
commonData[b[i]] = b[i];
}
}
print('${commonData.values}');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment