Skip to content

Latest commit

History

History
51 lines (34 loc) 路 1.57 KB

File metadata and controls

51 lines (34 loc) 路 1.57 KB

猬咃笍 Regresar

Reto #26: 馃幆 Calcula el porcentaje completado

Instrucciones

隆Santa Claus ya ha repartido todos los regalos! Ahora est谩 revisando los informes de productividad de los elfos. Pero hay un problema: la Product Owner, Mrs. Claus 馃鈥嶐煄勨湪, necesita entender r谩pidamente si los elfos cumplieron con los tiempos estimados. Est谩n haciendo Agile Scream.

Para ayudar a Mrs. Claus, tu tarea es calcular el porcentaje completado de cada tarea y devolverlo redondeado al n煤mero entero m谩s cercano. Esto le permitir谩 planificar mejor para la pr贸xima Navidad y mantener a todos contentos.

Esta es la funci贸n que espera:

getCompleted('01:00:00', '03:00:00') // 33%
getCompleted('02:00:00', '04:00:00') // 50%
getCompleted('01:00:00', '01:00:00') // 100%
getCompleted('00:10:00', '01:00:00') // 17%
getCompleted('01:10:10', '03:30:30') // 33%
getCompleted('03:30:30', '05:50:50') // 60%

馃巵 Ahora Santa Claus y los elfos merecen un descanso. 隆Esperamos que hayan disfrutado el AdventJS y lo recomienden a sus amigos!


Soluci贸n

function getCompleted(timeWorked, totalTime) {
  function timeToSeconds(time) {
    const [hours, minutes, seconds] = time.split(':').map(Number);
    return hours * 3600 + minutes * 60 + seconds;
  }

  return `${Math.round((timeToSeconds(timeWorked) / timeToSeconds(totalTime)) * 100)}%`;
}

Puntaje: 馃専馃専馃専馃専馃専

2074 ops/s

Complejidad cognitiva: 2


猬咃笍 Regresar