Skip to content

Instantly share code, notes, and snippets.

@paddya
Created December 10, 2011 18:07
Show Gist options
  • Save paddya/1455794 to your computer and use it in GitHub Desktop.
Save paddya/1455794 to your computer and use it in GitHub Desktop.
public Person findMostSimilarTo(Person p) {
Person bestMatch = null;
Profile ownProfile = this.getProfile(p);
int bestScore = 0;
for(int i = 0; i < this.profiles.length; i++) {
// don't compare the person with itself
if(p.equals(this.profiles[i].getOwner())) {
continue;
}
int currentScore = ownProfile.countSimilarities(this.profiles[i]);
if(currentScore > bestScore || bestMatch == null) {
bestScore = currentScore;
bestMatch = this.profiles[i].getOwner();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment