Skip to content

Commit

Permalink
Move lines
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Sep 12, 2021
1 parent 2d3ca1c commit 455a8b6
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions src/combination/ids.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,6 @@ import { titleColor, noteColor } from '../report/utils/colors.js'
import { DIMENSIONS, USER_DIMENSIONS } from './dimensions.js'
import { getInputIds } from './inputs.js'

export const hasSameCombinationIds = function (combinationA, combinationB) {
return DIMENSIONS.every(
({ idName }) => combinationA[idName] === combinationB[idName],
)
}

// Retrieve all unique combinations identifiers.
// For all combinations of a given result.
export const getCombinationsIds = function (combinations) {
return combinations.flatMap(getCombinationIds).filter(isNotSameDimDuplicate)
}

export const getCombinationName = function (combination) {
return getCombinationIds(combination)
.map(getCombinationNamePart)
Expand All @@ -30,22 +18,6 @@ const titleize = function (string) {
return `${string.charAt(0).toUpperCase()}${string.slice(1)}`
}

export const getCombinationIds = function (combination) {
return DIMENSIONS.map(({ dimension, idName }) => ({
dimension,
id: combination[idName],
}))
}

// Remove duplicate ids with the same dimension, since this happens due to the
// cartesian product.
// Duplicate ids with a different dimension are validated later.
const isNotSameDimDuplicate = function ({ dimension, id }, index, idInfos) {
return !idInfos
.slice(index + 1)
.some((idInfo) => idInfo.dimension === dimension && idInfo.id === id)
}

// Retrieve user-defined identifiers
export const getUserIds = function (combinations, inputs) {
const combinationsUserIds = getCombinationsIds(combinations).filter(isUserId)
Expand Down Expand Up @@ -74,3 +46,31 @@ const NON_COMBINATION_IDS = [
const listNonCombinationIds = function (dimension, getIds, inputs) {
return getIds(inputs).map((id) => ({ dimension, id }))
}

// Retrieve all unique combinations identifiers.
// For all combinations of a given result.
export const getCombinationsIds = function (combinations) {
return combinations.flatMap(getCombinationIds).filter(isNotSameDimDuplicate)
}

export const getCombinationIds = function (combination) {
return DIMENSIONS.map(({ dimension, idName }) => ({
dimension,
id: combination[idName],
}))
}

// Remove duplicate ids with the same dimension, since this happens due to the
// cartesian product.
// Duplicate ids with a different dimension are validated later.
const isNotSameDimDuplicate = function ({ dimension, id }, index, idInfos) {
return !idInfos
.slice(index + 1)
.some((idInfo) => idInfo.dimension === dimension && idInfo.id === id)
}

export const hasSameCombinationIds = function (combinationA, combinationB) {
return DIMENSIONS.every(
({ idName }) => combinationA[idName] === combinationB[idName],
)
}

0 comments on commit 455a8b6

Please sign in to comment.