Lag Shift
EasyData EngineeringArray
Description
Given an array and an offset k, shift every value forward by k positions (a lag). The first k positions become null and trailing values fall off the end.
Examples
Input:
[10,20,30,40], 1Output:
[null,10,20,30]Explanation:
Every value moves forward by the offset so each position now shows an earlier reading, with the opening positions left empty.
Input:
[1,2,3], 0Output:
[1,2,3]Explanation:
Every value moves forward by the offset so each position now shows an earlier reading, with the opening positions left empty.
Input:
[5,6,7], 2Output:
[null,null,5]Explanation:
Every value moves forward by the offset so each position now shows an earlier reading, with the opening positions left empty.
Constraints
- •
1 ≤ length ≤ 10⁴ - •
0 ≤ k ≤ length