private AgeDifference GetNormalizedAgeDifference(int i, int j) { var normalizedAgeDifference = new AgeDifference(); if (_persons[i].BirthDate < _persons[j].BirthDate) { normalizedAgeDifference.Person1 = _persons[i]; normalizedAgeDifference.Person2 = _persons[j]; } else { normalizedAgeDifference.Person1 = _persons[j]; normalizedAgeDifference.Person2 = _persons[i]; } normalizedAgeDifference.Difference = normalizedAgeDifference.Person2.BirthDate - normalizedAgeDifference.Person1.BirthDate; return normalizedAgeDifference; }
public AgeDifference Find(FindType findType) { var AgeDifferenceList = GetAgeDifferenceList(); AgeDifference ageDifferenceResult = new AgeDifference(); if (AgeDifferenceList.Count > 0) { if (findType == FindType.MaximumDiff) { AgeDifferenceList.Reverse(); } else { AgeDifferenceList.Sort(); } ageDifferenceResult = AgeDifferenceList[0]; } return ageDifferenceResult; }
public PairOfPeople Find(AgeDifference ageDifference) { PairOfPeople output = new PairOfPeople(); if (_allPeople.Count > 1) { var sortedPeople = SortPeopleByBirthDate(); var possibleOutput = new PairOfPeople[2] { GetSmallestAgeDifference(sortedPeople), GetLargestAgeDifference(sortedPeople) }; output = possibleOutput[(int)ageDifference]; } return(output); }