github.com/go-eden/common@v0.1.15-0.20210617133546-059099253264/emath/math_slice.go (about)

     1  package emath
     2  
     3  // DeleteUint16ByValue delete the first item from uint16 slice by value, then return the new slice.
     4  func DeleteUint16ByValue(arr []uint16, value uint16) []uint16 {
     5  	for i := 0; i < len(arr); i++ {
     6  		if arr[i] == value {
     7  			return DeleteUint16ByIndex(arr, i)
     8  		}
     9  	}
    10  	return arr
    11  }
    12  
    13  // DeleteUint16ByIndex Delete value from uint16 by its index, then return the new slice.
    14  func DeleteUint16ByIndex(arr []uint16, index int) []uint16 {
    15  	if index < len(arr)-1 {
    16  		copy(arr[index:], arr[index+1:])
    17  	}
    18  	return arr[:len(arr)-1]
    19  }