Use Iris' improved approach for determine most common cell sizes

pull/3088/head
Alex P 2018-03-30 11:20:12 -07:00
parent 330188c5cb
commit d247c11cd9
1 changed files with 16 additions and 16 deletions

View File

@ -26,23 +26,23 @@ export const NEW_DEFAULT_DASHBOARD_CELL = {
}
const getMostCommonValue = values => {
const distribution = {}
let max = 0
let result = 0
const results = values.reduce(
(acc, value) => {
const {distribution, mostCommonCount} = acc
distribution[value] = (distribution[value] || 0) + 1
if (distribution[value] > mostCommonCount) {
return {
distribution,
mostCommonCount: distribution[value],
mostCommonValue: value,
}
}
return acc
},
{distribution: {}, mostCommonCount: 0}
)
values.forEach(value => {
distribution[value] = (distribution[value] || 0) + 1
if (distribution[value] > max) {
max = distribution[value]
result = [value]
return
}
if (distribution[value] === max) {
result.push(value)
}
})
return result[0]
return results.mostCommonValue
}
export const generateNewDashboardCell = dashboard => {