moves getCycleLength to corresponding files, adds function to get next menses (not finished) with first tests

This commit is contained in:
tina
2018-08-22 18:21:57 +02:00
parent b80c91cb46
commit ea21fc92a2
5 changed files with 171 additions and 15 deletions
+13 -1
View File
@@ -1,6 +1,8 @@
import assert from 'assert'
import { LocalDate, ChronoUnit } from 'js-joda'
import cycleModule from '../lib/cycle'
export default function getCycleLengthStats(cycleLengths) {
export function getCycleLengthStats(cycleLengths) {
throwIfArgsAreNotInRequiredFormat(cycleLengths)
const cycleLengthStats = {}
const sortedCycleLengths = cycleLengths.sort((a, b) => {
@@ -46,4 +48,14 @@ function throwIfArgsAreNotInRequiredFormat(cycleLengths) {
assert.equal(typeof cycleLength, 'number', 'Elements in the array should be of type number.')
assert.ok(!isNaN(cycleLength), 'Elements of array should not be NaN.')
})
}
export function getCycleLength(cycleStartDates) {
const cycleLengths = []
for (let i = 0; i < cycleStartDates.length - 1; i++) {
const nextCycleStart = LocalDate.parse(cycleStartDates[i])
const cycleStart = LocalDate.parse(cycleStartDates[i + 1])
cycleLengths.push(cycleStart.until(nextCycleStart, ChronoUnit.DAYS))
}
return cycleLengths
}