Filtrar por calificación de estrellas
Dado un mapa de algunos elementos con calificaciones de estrellas y una calificación de estrellas específica, devuelve un nuevo mapa de elementos que coincidan con la calificación de estrellas especificada. Devuelve "No results found" si ningún elemento coincide con la calificación de estrellas indicada.
Ejemplos
filterByRating({
"Luxury Chocolates" : "*****",
"Tasty Chocolates" : "****",
"Aunty May Chocolates" : "*****",
"Generic Chocolates" : "***"
}, "*****") ➞ {
"Luxury Chocolates" : "*****",
"Aunty May Chocolates" : "*****"
}
filterByRating({
"Continental Hotel" : "****",
"Big Street Hotel" : "**",
"Corner Hotel" : "**",
"Trashviews Hotel" : "*",
"Hazbins" : "*****"
}, "*") ➞ {
"Trashviews Hotel" : "*"
}
filterByRating({
"Solo Restaurant" : "***",
"Finest Dinings" : "*****",
"Burger Stand" : "***"
}, "****") ➞ "No results found"Notas
N/A
Ejemplo en Java
assertEquals(java.util.Map.ofEntries(java.util.Map.entry("Brand K", "***"), java.util.Map.entry("Brand M", "***"), java.util.Map.entry("Brand O", "***")), Program.filterByRating(java.util.Map.ofEntries(java.util.Map.entry("Brand A", "*"), java.util.Map.entry("Brand B", "*****"), java.util.Map.entry("Brand C", "*"), java.util.Map.entry("Brand D", "**"), java.util.Map.entry("Brand E", "****"), java.util.Map.entry("Brand F", "*****"), java.util.Map.entry("Brand G", "****"), java.util.Map.entry("Brand H", "****"), java.util.Map.entry("Brand I", "*****"), java.util.Map.entry("Brand K", "***"), java.util.Map.entry("Brand L", "*****"), java.util.Map.entry("Brand M", "***"), java.util.Map.entry("Brand N", "*"), java.util.Map.entry("Brand O", "***"), java.util.Map.entry("Brand P", "*****"), java.util.Map.entry("Brand Q", "**"), java.util.Map.entry("Brand R", "****")), "***"));