Created
May 3, 2015 23:34
-
-
Save timwis/f24586ace7e43d6c6145 to your computer and use it in GitHub Desktop.
Election results kimono modification script
This file contains hidden or 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
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