From cf94d99129ec8537b5f57d4805aace3aa1c84d3d Mon Sep 17 00:00:00 2001 From: Daniel Tartavel Date: Fri, 23 Sep 2022 20:18:54 +0200 Subject: [PATCH] test --- methods/schulzeResults.php | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/methods/schulzeResults.php b/methods/schulzeResults.php index baed706..69fb437 100644 --- a/methods/schulzeResults.php +++ b/methods/schulzeResults.php @@ -33,19 +33,17 @@ class schulze $r = array(); foreach($votes as $vote) { - $r[] = implode($vote); + $r[] = implode("/", $vote); } return $r; } - function votify($votes) + function votify(&$votes) { - $r = array(); foreach($votes as $vote) { - $r[] = explode($vote); + $vote["vote"] = explode("/", $vote["vote"]); } - return $r; } function test($v) @@ -58,21 +56,17 @@ class schulze print_r($v); for($i = 0;$i < count($v) - 1;$i++) { + $s = $v[$i]; if ($i == 0) { - $w[$j]["vote"] = $v[$i]; - $w[$j]["n"] = 1; - $j += 1; + $w[$s] = 1; } - if ($v[$i] === $v[$i+1]) + if ($s == $v[$i+1]) { - $x = array_search($v[$i], $w); - $w[$x]["n"] += 1; + $w[$s] += 1; }else { - $w[$j]["vote"] = $v[$i+1]; - $w[$j]["n"] = 1; - $j += 1; + $w[$s] = 1; } } $w = votify($w);