Created
January 18, 2021 17:18
-
-
Save faustobdls/a2db6b74821d54202e6c820ea2c19a68 to your computer and use it in GitHub Desktop.
This file contains 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
void main() { | |
List<String> contatos = ['Fausto Blanco Diniz', 'Juselania Silva', 'Angela Maria', 'Ana', '']; | |
contatos = contatos.map( | |
(contato){ | |
String a = contato.split(' ').where((e) => e.isNotEmpty).toList().map( | |
(c) => c.substring(0,1) | |
).join(''); | |
// print(a); | |
if (a.isEmpty || a == '' || a.length == 1) { | |
return a; | |
} | |
if(a.length < 2){ | |
return a.substring(0, 1); | |
} | |
return a.substring(0, 2); | |
} | |
).toList(); | |
contatos.forEach(print); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment