DEV Community

loading...

Discussion on: Daily Challenge #61 - Evolution Rate

Collapse
savagepixie profile image
SavagePixie

Some JavaScript.

const getEvolutionRateMessage = (before, after) => {
   const evolution = before == 0 ? after * 100
   : after == 0 ? -before * 100
   : Math.round((after - before) / before * 100)

   return evolution == 0 ? "No evolution."
   : evolution > 0 ? `A positive evolution of ${evolution}℅.`
   : `A negative evolution of ${Math.abs(evolution)}%.`
}
Collapse
aminnairi profile image
Amin

Hi there, nice and short solution! I believe the case for the values 0 & 27.35 wont give what you expected. But you are in the right path for sure.

Collapse
savagepixie profile image