Skip to content

Commit

Permalink
small optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
linniksa committed Aug 18, 2012
1 parent 43affe6 commit 74583bb
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions Guess/Guess.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,17 @@ abstract class Guess
*/
public static function getBestGuess(array $guesses)
{
usort($guesses, function ($a, $b) {
return $b->getConfidence() - $a->getConfidence();
});
$result = null;
$maxConfidence = -1;

return count($guesses) > 0 ? $guesses[0] : null;
foreach ($guesses as $guess) {
if ($maxConfidence < $confidence = $guess->getConfidence()) {
$maxConfidence = $confidence;
$result = $guess;
}
}

return $result;
}

/**
Expand Down

0 comments on commit 74583bb

Please sign in to comment.