Skip to content

Commit

Permalink
code style Update Phpml\Math\Distance\Manhattan::distance() method. (…
Browse files Browse the repository at this point in the history
…#154)

I think this will be better.
  • Loading branch information
Qingshan Luo authored and akondas committed Nov 16, 2017
1 parent f7537c0 commit ff80af2
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions src/Phpml/Math/Distance/Manhattan.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,8 @@ public function distance(array $a, array $b) : float
throw InvalidArgumentException::arraySizeNotMatch();
}

$distance = 0;
$count = count($a);

for ($i = 0; $i < $count; ++$i) {
$distance += abs($a[$i] - $b[$i]);
}

return $distance;
return array_sum(array_map(function ($m, $n) {
return abs($m - $n);
}, $a, $b));
}
}

0 comments on commit ff80af2

Please sign in to comment.