News for hackers. Stuff that matters.
Re:Removing Array Duplicates by andrewla on Friday April 12, 2019 @09:35AM (#19644629)
This is the author's choice to make the problem hard -- Go has a built-in map type that works fine for this, and produces code as compact as the C++ version, and is also O(n):

  seen := make(map[string]bool)

  for n, s := range array {
    if seen[strings.ToLower(s)] {
      array[n] = ""
    } else {
      seen[strings.ToLower(s)] = true
    }
  }
Re:Removing Array Duplicates by rndgermandude on Friday April 12, 2019 @09:00PM (#19650384)
Don't calculate strings.ToLower() twice and skip over s == "" to avoid the map lookups and some assignments when already tombstoned and you'll save a lot of time.

    seen := make(map[string]bool)
    for n, s := range array {
        if s == "" {
            continue
        }
        lower := strings.ToLower(s)
        if seen[lower] {
            array[n] = ""
        } else {
            seen[lower] = true
        }
    }
Re:Removing Array Duplicates by minitech on Saturday April 13, 2019 @08:54AM (#19652739)
How can an element be already tombstoned? Isn’t that the first loop, making only one pass?
Re:Removing Array Duplicates by earthboundkid on Friday April 12, 2019 @09:59AM (#19644825)