Last active
August 21, 2020 06:37
-
-
Save velotiotech/972ee9dc0cfbcae341c1dab4ab794442 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
// API Response | |
[{ | |
symbol: 'SIC DIVISION', | |
exchange: 'Agricultural services', | |
volume: 42232, | |
}] | |
// Required format | |
[{ | |
category: 'Agricultural services', | |
name: 'SIC DIVISION', | |
y: 42232, | |
}] | |
const mapping = { | |
symbol: 'category', | |
exchange: 'name', | |
volume: 'y', | |
}; | |
const highchartsAdapter = (response, mapping) => { | |
return response.map(item => { | |
const normalized = {}; | |
// Normalize each response's item key, according to the mapping | |
Object.keys(item).forEach(key => (normalized[mapping[key]] = item[key])); | |
return normalized; | |
}); | |
}; | |
highchartsAdapter(response, mapping); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment