@tidyjs/tidy
Version:
Tidy up your data with JavaScript, inspired by dplyr and the tidyverse
14 lines (12 loc) • 394 B
JavaScript
function lag(key, options) {
const keyFn = typeof key === "function" ? key : (d) => d[key];
const {n = 1, default: defaultValue} = options != null ? options : {};
return (items) => {
return items.map((_, i) => {
const lagItem = items[i - n];
return lagItem == null ? defaultValue : keyFn(lagItem, i, items);
});
};
}
export { lag };
//# sourceMappingURL=lag.js.map