Ad
  • Custom User Avatar

    I update it to pass below test.

    Use a subslice as shallow copy doesn't work too.

      It("should not mutate source for any input", func() {
        data     := []int{1,5,87,45,8,8}
        expected := []int{1,5,87,45,8,8}
        TwoOldestAges(data)
        Expect(data).To(Equal(expected), 
          "Mutates %v", expected)
      })
    
  • Default User Avatar

    Thanks, I"m pretty new in golang world :) Love your solution!

  • Custom User Avatar

    sort mutates source.

    So to avoid side effects, it must be copied before use.