re: Daily Challenge #57 - BMI Calculator VIEW POST

TOP OF THREAD FULL DISCUSSION
re: Have you tested if your code is faster than a simpler conditional version (as most other solutions are written)?
 

Fair point Craig, in this case it turns out to be a bunch slower due to the complexity in indexFromBmi.
I just figured it was worth posting as an alternative approach as there are problems where luts are gold. In this case apparently not.

I'd say that here it's best to just use

function bmiLabel(weight, height) {
  const bmi = weight / height ** 2;
  return bmi <= 18.5 ? 'Underweight' : bmi <= 25 ? 'Normal' : bmi <= 30 ? 'Overweight' : 'Obese';
}

and be done with it.

code of conduct - report abuse