dropRight function
- List array,
- [int n = 1]
Creates a slice of array
with n
elements dropRightped from the beginning.
dropRight([1, 2, 3])
// => [1,2]
dropRight([1, 2, 3], 2)
// => [1]
dropRight([1, 2, 3], 5)
// => []
dropRight([1, 2, 3], 0)
// => [1, 2, 3]
Implementation
List dropRight(List array, [int n = 1]) {
n = array.length - n;
return array.isEmpty ? [] : slice(array, 0, n < 0 ? 0 : n);
}