Created
April 27, 2009 05:27
-
-
Save mikeyk/102344 to your computer and use it in GitHub Desktop.
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
function normalizeData(data){ | |
for (entry in data) { | |
var deduplicatedEntries = {}; | |
var originalData = data[entry]['data']; | |
for (var i = 0; i < originalData.length; i++) { | |
var keyindex = originalData[i][0]; | |
var value = originalData[i][1]; | |
deduplicatedEntries[keyindex] = (deduplicatedEntries[keyindex] || 0) + value; | |
} | |
var deduplicatedArray = []; | |
for (var key in deduplicatedEntries) { | |
var datapoint = [Number(key), deduplicatedEntries[key]]; | |
deduplicatedArray.push(datapoint); | |
} | |
deduplicatedArray.sort(function(a,b){return a[0] - b[0]}); | |
data[entry]['data'] = deduplicatedArray; | |
} | |
return data; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment