Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Dec 12, 2021
1 parent 0487935 commit d28827b
Showing 1 changed file with 5 additions and 16 deletions.
21 changes: 5 additions & 16 deletions src/stats/cold.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,7 @@ const COLD_MAX_PERCENTAGE = 0.6
// - This behavior is toggled by using `mean: undefined`
/* eslint-disable max-statements, complexity, fp/no-let, fp/no-loops,
fp/no-mutation, max-depth, no-continue */
const findClosestMean = function (
array,
{ mean, minIndex, maxIndex, filter, incrementalMeanMin, incrementalMeanMax },
) {
const findClosestMean = function (array, { mean, minIndex, maxIndex, filter }) {
let closestMean = 0
let closestMeanDiff = Number.POSITIVE_INFINITY
let sum = 0
Expand All @@ -155,19 +152,11 @@ const findClosestMean = function (
}

const incrementalMean = sum / filteredIndex
const meanDiff = Math.abs(mean - incrementalMean)

if (mean !== undefined) {
const meanDiff = Math.abs(mean - incrementalMean)

if (closestMeanDiff > meanDiff) {
closestMeanDiff = meanDiff
closestMean = incrementalMean
}
} else if (
incrementalMean >= incrementalMeanMin &&
incrementalMean <= incrementalMeanMax
) {
return
if (closestMeanDiff > meanDiff) {
closestMeanDiff = meanDiff
closestMean = incrementalMean
}
}

Expand Down

0 comments on commit d28827b

Please sign in to comment.