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

TypeNameDefaultDescription
ReallistList of values to be shifted
IntegernNumber of steps to shift the list( n < 0 => shift to the left)
Realfill0Value to fill the gaps with (default = 0)

Outputs

TypeNameDefaultDescription
RealshiftedListShifted list
RealcarrySum of elements that were pushed out of range by the shift

Revisions

  • Added Inline = true in v2.1.0.