Skip to content

Instantly share code, notes, and snippets.

@faustobdls
Created January 18, 2021 17:18
Show Gist options
  • Save faustobdls/a2db6b74821d54202e6c820ea2c19a68 to your computer and use it in GitHub Desktop.
Save faustobdls/a2db6b74821d54202e6c820ea2c19a68 to your computer and use it in GitHub Desktop.
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