Created with <3 with dartpad.dev.
Created
October 31, 2023 02:34
-
-
Save leonus96/4491cd44db1ab88b86983921058359b8 to your computer and use it in GitHub Desktop.
4. Duplicados
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
/// Ejercicio 4: Eliminar Elementos | |
/// Duplicados | |
/// Escribe una función que elimine los | |
/// elementos duplicados de una lista. | |
void main() { | |
final List<int> numeros = [2, 4, 6, 1, 2, 3, 5, 67, 23, 5, 2]; | |
print(eliminarDuplicadosManualmente(numeros)); | |
} | |
List<int> eliminarDuplicados(List<int> numeros) { | |
return numeros.toSet().toList(); | |
} | |
List<int> eliminarDuplicadosManualmente(List<int> numeros) { | |
List<int> sinDuplicados = []; | |
for (int numero in numeros) { | |
if(!sinDuplicados.contains(numero)) { | |
sinDuplicados.add(numero); | |
} | |
} | |
return sinDuplicados; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment