Created with <3 with dartpad.dev.
Last active
January 18, 2023 22:10
-
-
Save Wils0nDev/aea2b359e44b1c16a343de6ba23e0674 to your computer and use it in GitHub Desktop.
Dart-Colecciones-Reto
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
void main() { | |
Set restaurantes = { | |
{ | |
"nombre": "El novillo alegre", | |
"tipo": "Argentina", | |
"calificaciones": [4, 5, 2, 1, 2] | |
}, | |
{ | |
"nombre": "Baires Grill", | |
"tipo": "Argentina", | |
"calificaciones": [3, 1, 3, 5, 5, 2, 3] | |
}, | |
{ | |
"nombre": "Mario Brothers", | |
"tipo": "Italiana", | |
"calificaciones": [4, 3, 2, 1, 1] | |
}, | |
{ | |
"nombre": "Molto bene", | |
"tipo": "Italiana", | |
"calificaciones": [4, 3, 1, 1, 5] | |
}, | |
}; | |
Map resumen = {}; | |
String type = ''; | |
List<int> calificacionesArg = []; | |
List<int> calificacionesIta = []; | |
double lengArg = 0; | |
double lengIta = 0; | |
double sumCalificacionesArg = 0; | |
double sumCalificacionesIta = 0; | |
for (int i = 0; i < restaurantes.length; i++) { | |
type = restaurantes.elementAt(i)['tipo']; | |
if (type == "Argentina") { | |
calificacionesArg.addAll(restaurantes.elementAt(i)['calificaciones']); | |
lengArg = | |
lengArg + [...restaurantes.elementAt(i)['calificaciones']].length; | |
sumCalificacionesArg = | |
sumCalificacionesArg + (calificacionesArg.reduce((a, b) => a + b)); | |
} | |
if (type == "Italiana") { | |
calificacionesIta.addAll(restaurantes.elementAt(i)['calificaciones']); | |
lengIta = | |
lengIta + [...restaurantes.elementAt(i)['calificaciones']].length; | |
sumCalificacionesIta = | |
sumCalificacionesIta + (calificacionesIta.reduce((a, b) => a + b)); | |
} | |
calificacionesArg.clear(); | |
calificacionesIta.clear(); | |
} | |
resumen.addAll({ | |
"Argentina": sumCalificacionesArg / lengArg, | |
"Italiana": sumCalificacionesIta / lengIta, | |
'Todos': ((sumCalificacionesArg + sumCalificacionesIta ) / (lengArg + lengIta)).toStringAsFixed(2) | |
}); | |
print(resumen); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment