DeepEqual in golang for slice

package main

import (
"fmt"
"reflect"
)

func main() {
a := []int{1,2,3}
b := []int{1,2,3}
fmt.Println(reflect.DeepEqual(a, b))

        a = []int{1,2,4}
b = []int{1,2,3}
fmt.Println(reflect.DeepEqual(a, b))

        a = []int{1}
b = []int{1,2,3}
fmt.Println(reflect.DeepEqual(a, b))

}
Note: Only use for testing 



// Equal tells whether a and b contain the same elements.
// A nil argument is equivalent to an empty slice.
func Equal(a, b []int) bool {
    if len(a) != len(b) {
        return false
    }
    for i, v := range a {
        if v != b[i] {
            return false
        }
    }
    return true
}


a := [2]int{1, 2}
b := [2]int{1, 3}
fmt.Println(a == b) // false

Comments

Popular posts from this blog

Fixing the DeepSpeed Import Error While Fine-Tuning the Qwen Model

Amazon Linux 2023 - User data configuration for launch templates to connect to the EKS cluster

How to create ISM policy and rotate logs in opensearch