Skip to content

Instantly share code, notes, and snippets.

@nathggns
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathggns/d97ef068c9cb7cc34fe1 to your computer and use it in GitHub Desktop.
Save nathggns/d97ef068c9cb7cc34fe1 to your computer and use it in GitHub Desktop.
Calculate how many majority seats each party gained
<?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