@tidyjs/tidy
Version:
Tidy up your data with JavaScript, inspired by dplyr and the tidyverse
19 lines (17 loc) • 664 B
JavaScript
function roll(width, rollFn, options) {
const {partial = false, align = "right"} = options != null ? options : {};
const halfWidth = Math.floor(width / 2);
return (items) => {
return items.map((_, i) => {
const endIndex = align === "right" ? i : align === "center" ? i + halfWidth : i + width - 1;
if (!partial && (endIndex - width + 1 < 0 || endIndex >= items.length)) {
return void 0;
}
const startIndex = Math.max(0, endIndex - width + 1);
const itemsInWindow = items.slice(startIndex, endIndex + 1);
return rollFn(itemsInWindow, endIndex);
});
};
}
export { roll };
//# sourceMappingURL=roll.js.map