UNPKG

@tidyjs/tidy

Version:

Tidy up your data with JavaScript, inspired by dplyr and the tidyverse

18 lines (14 loc) 476 B
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); 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); }); }; } exports.lag = lag; //# sourceMappingURL=lag.js.map