Skip to content

Commit

Permalink
Move code
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Dec 12, 2021
1 parent 1b701fc commit e317f63
Showing 1 changed file with 40 additions and 40 deletions.
80 changes: 40 additions & 40 deletions src/stats/cold.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,46 +68,6 @@ const defaultFilter = function () {
return true
}

/* eslint-disable max-statements, complexity, fp/no-let, fp/no-loops,
fp/no-mutation, max-depth, no-continue */
const getClosestMeanIndex = function (
array,
{ minIndex, maxIndex, filter, incrementalMeanMin, incrementalMeanMax },
) {
let sum = 0
let index = -1
let filteredIndex = 0

while (filteredIndex <= maxIndex) {
index += 1
const value = array[index]

if (!filter(value)) {
continue
}

filteredIndex += 1
sum += value

if (filteredIndex <= minIndex) {
continue
}

const incrementalMean = sum / filteredIndex

if (
incrementalMean >= incrementalMeanMin &&
incrementalMean <= incrementalMeanMax
) {
return index
}
}

return maxIndex
}
/* eslint-enable max-statements, complexity, fp/no-let, fp/no-loops,
fp/no-mutation, max-depth, no-continue */

const getIndexFromLength = function (percentage, length) {
return Math.floor(percentage * (length - 1))
}
Expand Down Expand Up @@ -189,3 +149,43 @@ const getClosestMean = function (array, { mean, minIndex, maxIndex, filter }) {
}
/* eslint-enable max-statements, complexity, fp/no-let, fp/no-loops,
fp/no-mutation, max-depth, no-continue */

/* eslint-disable max-statements, complexity, fp/no-let, fp/no-loops,
fp/no-mutation, max-depth, no-continue */
const getClosestMeanIndex = function (
array,
{ minIndex, maxIndex, filter, incrementalMeanMin, incrementalMeanMax },
) {
let sum = 0
let index = -1
let filteredIndex = 0

while (filteredIndex <= maxIndex) {
index += 1
const value = array[index]

if (!filter(value)) {
continue
}

filteredIndex += 1
sum += value

if (filteredIndex <= minIndex) {
continue
}

const incrementalMean = sum / filteredIndex

if (
incrementalMean >= incrementalMeanMin &&
incrementalMean <= incrementalMeanMax
) {
return index
}
}

return maxIndex
}
/* eslint-enable max-statements, complexity, fp/no-let, fp/no-loops,
fp/no-mutation, max-depth, no-continue */

0 comments on commit e317f63

Please sign in to comment.