Permalink
Browse files

small optimization

  • Loading branch information...
1 parent 43affe6 commit 74583bb7a8ed758c29431b4900467db04ddd0b32 @linniksa linniksa committed Aug 18, 2012
Showing with 10 additions and 4 deletions.
  1. +10 −4 Guess/Guess.php
View
@@ -79,11 +79,17 @@
*/
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;
}
/**

0 comments on commit 74583bb

Please sign in to comment.