DROP (Array, Count) DROP (Array; Count)

Array

The array whose elements should be removed.

Count

Number Number

The number of elements to remove. A positive count removes elements from the beginning of the array and a negative count removes elements from the end.

Returns

The given array, with the first or last elements removed.

Returns the given array with the first or last elements removed. DROP ({ 10, 20, 30 }, 1) DROP ({ 10; 20; 30 }; 1) removes the first element and returns { 20, 30 }{ 20; 30 }.

Removing elements from the end

A negative count removes elements from the end of the array instead of from the beginning. This formula removes the last element and returns { 10, 20 }{ 10; 20 }:

DROP ({ 10, 20, 30 }, - 1)
DROP ({ 10; 20; 30 }; - 1)

Naming the parameter often makes the intent clearer:

DROP (SomeArray, Count: 2)
DROP (SomeArray; Count: 2)

Counts of zero and counts which are too large

A count of zero does not remove anything and returns the array unchanged.

A count larger than the number of elements in the array is not an error. Every element is removed and an empty array is returned. This formula returns an empty array:

DROP ({ 10, 20, 30 }, 100)
DROP ({ 10; 20; 30 }; 100)

DROP, TAKE and FILTER

TAKE is the counterpart of this function and returns the elements which DROP removes. Given the same array and the same count, the two functions divide the array between them.

DROP and TAKE both select elements by position . An author who needs to select elements by condition should instead use FILTER, which tests every element and keeps the ones matching the condition.

Examples

DROP ({ 10, 20, 30 }, 1)
DROP ({ 10; 20; 30 }; 1)

Returns { 20, 30 }{ 20; 30 }, having removed the first element.

DROP ({ 10, 20, 30 }, 2)
DROP ({ 10; 20; 30 }; 2)

Returns { 30 }{ 30 }, having removed the first two elements.

DROP ({ 10, 20, 30 }, - 1)
DROP ({ 10; 20; 30 }; - 1)

Returns { 10, 20 }{ 10; 20 }, having removed the last element.

DROP ({ 10, 20, 30 }, 0)
DROP ({ 10; 20; 30 }; 0)

Returns { 10, 20, 30 }{ 10; 20; 30 }, without removing anything.

DROP ({ 10, 20, 30 }, 100)
DROP ({ 10; 20; 30 }; 100)

Returns an empty array. A count larger than the number of elements is not an error.

DROP (Matrix, RowCount, ColumnCount) DROP (Matrix; RowCount; ColumnCount)

Matrix

The two-dimensional array whose rows and columns should be removed.

RowCount

Number Number

The number of rows to remove. A positive count removes rows from the beginning, a negative count removes rows from the end and zero leaves the rows untouched.

ColumnCount

Number Number

The number of columns to remove from every remaining row. A positive count removes columns from the beginning, a negative count removes columns from the end and zero leaves the columns untouched.

Returns

The given two-dimensional array, with the first or last rows and columns removed.

Returns the given two-dimensional array with the first or last rows and columns removed. DROP ({ { 10, 20 }, { 30, 40 } }, 1, 0) DROP ({ { 10; 20 }; { 30; 40 } }; 1; 0) removes the first row and returns { { 30, 40 } }{ { 30; 40 } }.

The two counts are independent of one another. Either may be negative, removing rows or columns from the end instead of from the beginning, and either may be zero, leaving that axis untouched. This formula removes the first row and the last column:

DROP ({ { 10, 20 }, { 30, 40 } }, 1, - 1)
DROP ({ { 10; 20 }; { 30; 40 } }; 1; - 1)

As both counts must be given, zero is how an author says that one axis should be left alone. Naming the parameters makes this easier to read:

DROP (SomeMatrix, RowCount: 0, ColumnCount: 1)
DROP (SomeMatrix; RowCount: 0; ColumnCount: 1)

If every row or every column is removed, an empty array is returned.

Examples

DROP ({ { 10, 20 }, { 30, 40 } }, 1, 0)
DROP ({ { 10; 20 }; { 30; 40 } }; 1; 0)

Returns { { 30, 40 } }{ { 30; 40 } }, having removed the first row and left the columns untouched.

DROP ({ { 10, 20 }, { 30, 40 } }, 0, 1)
DROP ({ { 10; 20 }; { 30; 40 } }; 0; 1)

Returns { { 20 }, { 40 } }{ { 20 }; { 40 } }, having removed the first column of every row and left the rows untouched.

DROP ({ { 10, 20 }, { 30, 40 } }, 1, - 1)
DROP ({ { 10; 20 }; { 30; 40 } }; 1; - 1)

Returns { { 30 } }{ { 30 } }, having removed the first row and the last column.

fxEngine Shell Want this in your own terminal? A standalone version is coming. Get notified.
Loading fxEngine Shell