Snippets Collections
// ReversePartial reverses a portion of a slice in place from start to end (-1 for end of list) indices.
func ReversePartial[T any](arr []T, start, end int) error {
	if end == -1 {
		end = len(arr) - 1
	}
	// Validate indices
	if start < 0 || end >= len(arr) || start >= end {
		return fmt.Errorf("Invalid start or end indices")
	}

	for start < end {
		arr[start], arr[end] = arr[end], arr[start] // Swap elements
		start++
		end--
	}
	return nil
}
// Reverse returns a new slice with the elements of the input slice in reverse order.
func Reverse[T any](arr []T) []T {
	n := len(arr)
	reversed := make([]T, n) // Create a new slice of the same length

	for i := 0; i < n; i++ {
		reversed[i] = arr[n-1-i] // Copy elements from end to start
	}

	return reversed
}
// Reverse reverses any slice of any type.
func ReverseInplace[T any](arr []T) {
	n := len(arr)
	for i := 0; i < n/2; i++ {
		arr[i], arr[n-1-i] = arr[n-1-i], arr[i]
	}
}
wget https://dl.google.com/go/go1.21.0.linux-amd64.tar.gz
sudo tar -xvf go1.21.0.linux-amd64.tar.gz
sudo mv go /usr/local
sudo ln -s /usr/local/go/bin/* /usr/bin
rm go1.21.0.linux-amd64.tar.gz
export GOPATH=$HOME/go
export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin
star

Wed Oct 30 2024 03:59:23 GMT+0000 (Coordinated Universal Time)

#go #golang
star

Wed Oct 30 2024 03:49:20 GMT+0000 (Coordinated Universal Time)

#go #golang
star

Wed Oct 30 2024 03:46:27 GMT+0000 (Coordinated Universal Time)

#go #golang
star

Sat Sep 02 2023 12:08:22 GMT+0000 (Coordinated Universal Time)

#ubuntu #linux #go #golang
star

Thu Aug 17 2023 15:42:53 GMT+0000 (Coordinated Universal Time) https://www.codinguru.online/compiler/go

#go #golang #compiler #codinguru

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension