3
I have a function to search a json locally and change the data of some Fields. however, I do not want to test if the field is with the status code and depending I change with the correct value for visualization in the frontend.
following example:
  $http.get("http://localteste:18888/tess").success(function (dados) {
         local_locations = $.map(dados, function (dev) {
            //Verifica Status da Bateria
            if (dev.status) {
                if (dev.status <= 10)
                    dev.status= "Muito Baixo";
               else if (dev.status<= 25)
                    dev.status = "Baixo";;
               else if ((dev.status== 50) || (dev.status>= 25))
                    dev.status= "Medio";;
              else  if ((dev.status== 75) || (dev.status>= 50))
                    dev.status= "Alto";;
               else if ((dev.status== 100) || (dev.status> 75))
                    dev.batUseBattery = "Muito alto";
       }
 });
That would be about right, but there’s a lot of tests like that. How could I improve?
What’s the point of reducing the number of if? Is it just because of reading? Regarding algorithmic complexity there is no problem.
– Nbento