diff --git a/src/predict/predict_class.js b/src/predict/predict_class.js index 85f30ca..b33c07d 100644 --- a/src/predict/predict_class.js +++ b/src/predict/predict_class.js @@ -161,6 +161,11 @@ class Predict { //find index of y peak const { peak , peakIndex } = this.getLocalPeak(curve.y); + // Guard against invalid peakIndex (e.g. empty array returns -1) + if (peakIndex < 0 || peakIndex >= curve.x.length) { + return { yPeak: null, x: null, xProcent: null }; + } + // scale the x value to procentual value const yPeak = peak; const x = curve.x[peakIndex];