Code through the looking glassAnd a linear search to rule them

time to read 1 min | 187 words

The final piece for this candidate is the code to actually search through the sorted array. As you'll recall, the candidate certainly made our computer pay for that sorting and merging. But we are fine now, we have manage to recover from all of that abuse, and we are ready to rock.

Here is how the search (over sorted array) was implemented.

public List<int> EmailSearcher(string email)
{
    List<int> answer = new List<int>();
    for (int i = 0; i < emailsArray.Length; i++)
    {
        if (emailsArray[i].STR.ToString().Equals(email, StringComparison.OrdinalIgnoreCase))
        {
            answer = emailsArray[i].ID;
            return answer;
        }
    }

    return answer;
}

And with that, I have nothing left to say.

More posts in "Code through the looking glass" series:

  1. (18 Mar 2016) And a linear search to rule them
  2. (17 Mar 2016) Sorting large data sets
  3. (16 Mar 2016) I'm the God of all OOP
  4. (15 Mar 2016) All you need is a dictionary (and O(N) )
  5. (14 Mar 2016) Finding today's log file