Comparing Maps in Go Language

Meet Raval
Feb 12, 2022

--

It’s not that hard when you use Reflect Package

Solution

There are 2 main things:
1. Importing the “reflect” package:

import “reflect”

2. using DeepEqual Function:

reflect.DeepEqual(map1, map2)

DeepEqual Function will compare each key and value pair of two maps with each other.

// So, the output of the Above Code Snippet would be:// Print: map1 & map2
map[a:1 b:2] map[a:1 b:2]
// reflect.DeepEqual's Output
true

If both the maps (map1 & map2) has the same key: value pair then it will return True.

Else it will return False.

Time Complexity of this Function is O(N)

--

--

Meet Raval

Software Developer at Arctic Wolf. Want to make the world a better place.