DEV Community

Discussion on: Daily Challenge #61 - Evolution Rate

Collapse
 
cgty_ky profile image
Cagatay Kaya

Here is a Javascript arrow function, that uses nested ternary operators. Someone probably already posted this answer, but hey main point is that I took the challenge and solved by myself.

const getEvolutionRateMessage = (before, after) => {
  const rate = Math.round(
    (((after == 0 ? -before * before + before : after) - before) /
      (before == 0 ? 1 : before)) *
      100
  );
  return rate == 0
    ? "No evolution."
    : rate > 0
    ? `A positive evolution of ${rate}%.`
    : `A negative evolution of ${-1 * rate}%.`;
};
Collapse
 
aminnairi profile image
Amin

Thanks for showing us your solution. What's important is what you achieve at the end of the day!