Created
March 29, 2019 04:26
-
-
Save cstefanache/50903d115700d666998c4750d938e495 to your computer and use it in GitHub Desktop.
Data parsing
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
let data = [ | |
['356.0','Ailment_6','sleep pain back','food concentrate'], | |
['356.0','Ailment_2','sick feel','food healthy'], | |
['356.0','Ailment_10','cramps eyes', 'ibuprofen'], | |
['357.0','Ailment_4','back sick knee', 'biking eat'], | |
['357.0','Ailment_6','sick joint', 'juice nutrient'], | |
['357.0','Ailment_8','hurt heart', 'ibuprofen'] | |
].reduce( (memo, item) => { | |
console.log(item); | |
const [ state, ailment, symptoms, treatments ] = item; | |
let data = memo[parseInt(state)]; | |
if (!data) { | |
data = memo[parseInt(state)] = []; | |
} | |
data.push(`Ailment: ${ailment}`) | |
data.push(`Symptoms: ${symptoms}`) | |
data.push(`Treatments: ${treatments}`) | |
return memo; | |
}, {}); | |
console.log(data); | |
/** | |
{ | |
"356":["Ailment: Ailment_6","Symptoms: sleep pain back","Treatments: food concentrate","Ailment: Ailment_2","Symptoms: sick feel","Treatments: food healthy","Ailment: Ailment_10","Symptoms: cramps eyes","Treatments: ibuprofen"], | |
"357":["Ailment: Ailment_4","Symptoms: back sick knee","Treatments: biking eat","Ailment: Ailment_6","Symptoms: sick joint","Treatments: juice nutrient","Ailment: Ailment_8","Symptoms: hurt heart","Treatments: ibuprofen"]} | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment