Last active
August 29, 2015 14:21
-
-
Save nathggns/d97ef068c9cb7cc34fe1 to your computer and use it in GitHub Desktop.
Calculate how many majority seats each party gained
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$json = file_get_contents('https://gist.githubusercontent.com/nathggns/051203c3d7e72159de0d/raw/9e368d3a99a219a7fc487d327b86ebd4f6c8ed53/results.json') or die('Cannot fetch data'); | |
$consts = json_decode($json, true) or die('Cannot decode data'); | |
var_dump(array_reduce(array_map(function($const_name) use ($consts) { | |
return [$consts[$const_name][0]['name'], $const_name]; | |
}, array_filter(array_keys($consts), function($const_name) use($consts) { | |
return $consts[$const_name][0]['share'] >= 0.5; | |
})), function($data, $pair) { | |
$data[$pair[0]][] = $pair[1]; | |
return $data; | |
}, [])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment