@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.
39 lines (28 loc) • 1.53 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
var countValues = function countValues(data, _ref, min) {
var _ref2 = _slicedToArray(_ref, 2),
from = _ref2[0],
to = _ref2[1];
return data.reduce(function (_ref3, curr, index) {
var _ref4 = _slicedToArray(_ref3, 2),
selected = _ref4[0],
totalCount = _ref4[1];
return [index + min >= from && index + min <= to ? selected + curr : selected, totalCount + curr];
}, [0, 0]);
};
var calculateCountOf = function calculateCountOf(data, value, min) {
if (Array.isArray(value)) {
return countValues(data, [value[0], value[value.length - 1]], min);
}
return countValues(data, [min, value], min);
};
var _default = calculateCountOf;
exports.default = _default;