Compare Two Lists in Go

Posted by yhuang
Public (Editable by Users)
Go
Edit
package main

import (
	"fmt"
)

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
}

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