The array of interest.
The predicate function to apply to the values.
The index of the first element in the range to be
searched, inclusive. The default value is -1
. Negative values
are taken as an offset from the end of the array.
The index of the last element in the range to be
searched, inclusive. The default value is 0
. Negative values
are taken as an offset from the end of the array.
The removed { index, value }
, which will be -1
and
undefined
if the value is not contained in the array.
If start < stop
the search will wrap at the end of the array.
Linear.
import { ArrayExt } from '@lumino/algorithm';
function isEven(value: number): boolean {
return value % 2 === 0;
}
let data = [0, 12, 23, 39, 14, 12, 75];
ArrayExt.removeLastWhere(data, isEven); // { index: 5, value: 12 }
ArrayExt.removeLastWhere(data, isEven, 2); // { index: 1, value: 12 }
ArrayExt.removeLastWhere(data, isEven, 2, 1); // { index: -1, value: undefined }
Remove the last occurrence of a value which matches a predicate.