Skip to content

Instantly share code, notes, and snippets.

@timwis
Created May 3, 2015 23:34
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 timwis/f24586ace7e43d6c6145 to your computer and use it in GitHub Desktop.
Save timwis/f24586ace7e43d6c6145 to your computer and use it in GitHub Desktop.
Election results kimono modification script
function transform(data) {
var newCandidates = [];
var raceIndex = -1; // start at -1 since first index is 0
// Loop through candidates
data.results.candidates.forEach(function(row, index) {
if(row.candidate === 'Candidate Name') {
raceIndex++;
} else {
row.race = data.results.races[raceIndex].race;
newCandidates.push(row);
}
});
// Delete the headers (messes up loop if done above)
data.results.candidates = newCandidates;
return data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment