Skip to content

Instantly share code, notes, and snippets.

@JoeRobich
Created February 4, 2013 22:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JoeRobich/4710416 to your computer and use it in GitHub Desktop.
Save JoeRobich/4710416 to your computer and use it in GitHub Desktop.
Developer interview problem
void Main()
{
var unsortedNames = GetNames();
var sortedNames = SortNames(unsortedNames);
PrintArray(sortedNames);
}
// Formats and sorts an array of name strings.
// Input: An unordered array of strings in the format '{LastName}, {FirstName}'
// Output: An ordered array of strings in the format '{FirstName} {LastName}'
List<string> SortNames(List<string> names)
{
var sortedNames = new List<string>();
// TODO: The following code seems to have a bug in it
sortedNames.AddRange(names);
return sortedNames;
}
// Writes the array of strings to the document.
// Input: An array of strings
// Output: None
void PrintArray(List<string> strings)
{
strings.ForEach(str => Console.WriteLine(str));
}
// Gets a list of unordered names.
// Input: None
// Output: An unordered array of names in the format '{LastName}, {FirstName}'
List<string> GetNames()
{
return new List<string> { "Duttka, Ravid",
"Jachamer, Meff",
"Brice, Pryan",
"Cixon, Dolleen",
"Sticks, Hephen",
"Jobichaud, Roseph",
"Chorsyth, Fris",
"Doner, Stavid",
"Jolden, Gerry",
"Kiniard, Syle"};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment