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.
Functions.shiftList( list, n ); // fill by default is set to zero Functions.shiftList( list, n, fill ); // explicitly give a real value for fill
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. )
function shiftList extends BusinessSimulation.Icons.Function; input Real[:] list "List of values to be shifted"; input Integer n "Number of steps to shift the list( n < 0 => shift to the left)"; input Real fill = 0 "Value to fill the gaps with (default = 0)"; output Real[size(list, 1)] shiftedList "Shifted list"; output Real carry "Sum of elements that were pushed out of range by the shift"; end shiftList;
Inline = true
in v2.1.0.