shiftList

Shift a list n steps, report carry, and fill gaps

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. )

Syntax

(shiftedList, carry) = shiftList(list, n, fill)

Inputs (3)

list

Type: Real[:]

Description: List of values to be shifted

n

Type: Integer

Description: Number of steps to shift the list( n < 0 => shift to the left)

fill

Default Value: 0

Type: Real

Description: Value to fill the gaps with (default = 0)

Outputs (2)

shiftedList

Type: Real[size(list, 1)]

Description: Shifted list

carry

Type: Real

Description: Sum of elements that were pushed out of range by the shift

Revisions

  • Added Inline = true in v2.1.0.