Skip to content

Instantly share code, notes, and snippets.

@cstefanache
Created March 29, 2019 04:26
Show Gist options
  • Save cstefanache/50903d115700d666998c4750d938e495 to your computer and use it in GitHub Desktop.
Save cstefanache/50903d115700d666998c4750d938e495 to your computer and use it in GitHub Desktop.
Data parsing
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