DEV Community

loading...

Discussion on: Daily Challenge #61 - Evolution Rate

Collapse
cvanpoelje profile image
cvanpoelje

My javascript solution :

const getEvolutionRateMessage = (before, after) => {
  evolution =
    before > 0 ? ((after - before) / before) * 100 : (after - before) * 100;
  return evolution === 0
    ? "No Evolution"
    : `A ${evolution > 0 ? "Positive" : "Negative"} evolution of ${Math.abs(
        evolution
      ).toFixed(2)}%`;
}