title: DeDuplicate Array of Structs
body: <p>I have an array of struct and I want to remove all the duplicates element but keep the last element in the array. Something similar to hashmap where I can update the last struct matched every time to the new array</p>
  
  <p>I have a struct something like this </p>
  
  <pre><code>type samplestruct struct {
      value1           string    
      value2           string   
      value3           string   
      value4           string
      value5           string
  }
  </code></pre>
  
  <p>In my array of struct if value1, value2 and value3 of any struct is same , remove all the duplicates and keep the last struct.</p>
  
  <pre><code>func unique(sample []samplestruct) []samplestruct {
      var unique []samplestruct
  
      for _, v := range sample {
          skip := false
          for _, u := range unique {
              if v.value1 == u.value1 &amp;&amp; v.value2 == u.value2 &amp;&amp; v.value3 == u.value3 {
                  skip = true
                  break
              }
          }
          if !skip {
              unique = append(unique, v)
          }
      }
      return unique
  
  }
  </code></pre>
  
  <p>This code return me the first struct that matched the condition provided but I want the last struct that matches the condition</p>
  
  <p>Given Input -</p>
  
  <pre><code>[
  samplestruct{"ram","rahim","india","34","india"},
  samplestruct{"ram","rahim","india","38","America"},
  samplestruct{"ram","rahim","india","40","Jamica"},
  samplestruct{"amit","rawat","bangladesh","35","hawai"},
  samplestruct{"amit","rawat","bangladesh","36","india"}
  ]
  </code></pre>
  
  <p>ExpectedOutput - </p>
  
  <pre><code>[
  samplestruct{"ram","rahim","india","40","Jamica"},
  samplestruct{"amit","rawat","bangladesh","36","india"}
  ]
  </code></pre>