Go ElementsEqual()

1 개요[ | ]

Go ElementsEqual()
package main

import (
	"fmt"

	"github.com/google/go-cmp/cmp"
	"github.com/google/go-cmp/cmp/cmpopts"
)

func main() {
	a := []int{1, 2, 11, 12}
	b := []int{12, 2, 1, 11}
	fmt.Println(intElementsEqual(a, b)) // true

	x := []string{"a", "b", "c"}
	y := []string{"a", "c", "b"}
	fmt.Println(stringElementsEqual(x, y)) // true

}

func intElementsEqual(a, b []int) bool {
	return cmp.Diff(a, b, cmpopts.SortSlices(func(x, y int) bool { return x < y })) == ""
}

func stringElementsEqual(a, b []string) bool {
	return cmp.Diff(a, b, cmpopts.SortSlices(func(x, y string) bool { return x < y })) == ""
}


2 같이 보기[ | ]

3 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}