functionshiftList
Shift a list n steps, report carry, and fill gaps
Extends from BusinessSimulation.Icons.Function (Icon for functions).
Information
This information is part of the Business Simulation Library (BSL). Please support this work and ► donate.
The function will return a list shifted by n places (n < 0 ⇒ shift to the left), where the elements "pushed" out of range are added up and reported as carry. The gaps will be shifted with the real value fill, which by default is set to 0.
Syntax
Functions.shiftList( list, n ); // fill by default is set to zero Functions.shiftList( list, n, fill ); // explicitly give a real value for fill
Examples
shiftList( {1, 2, 3, 4, 5}, 0); // ( {1, 2, 3, 4, 5}, 0. )
shiftList( {1, 2, 3, 4, 5}, -2); // ( {3, 4, 5, 0, 0}, 3. )
shiftList( {1, 2, 3, 4, 5}, 2); // ( {0, 0, 1, 2, 3}, 9. )Inputs
| Type | Name | Default | Description |
|---|---|---|---|
| Real | list | List of values to be shifted | |
| Integer | n | Number of steps to shift the list( n < 0 => shift to the left) | |
| Real | fill | 0 | Value to fill the gaps with (default = 0) |
Outputs
| Type | Name | Default | Description |
|---|---|---|---|
| Real | shiftedList | Shifted list | |
| Real | carry | Sum of elements that were pushed out of range by the shift |
Revisions
- Added
Inline = truein v2.1.0.