@kiwicom/orbit-components
Version:
Orbit-components is a React component library which provides developers with the easiest possible way of building Kiwi.com’s products.
13 lines (10 loc) • 455 B
JavaScript
const countValues = (data, [from, to], min) => data.reduce(([selected, totalCount], curr, index) => {
return [index + min >= from && index + min <= to ? selected + curr : selected, totalCount + curr];
}, [0, 0]);
const calculateCountOf = (data, value, min) => {
if (Array.isArray(value)) {
return countValues(data, [value[0], value[value.length - 1]], min);
}
return countValues(data, [min, value], min);
};
export default calculateCountOf;