Skip to content

Instantly share code, notes, and snippets.

@fchevitarese
Created July 30, 2015 15:18
Show Gist options
  • Save fchevitarese/ef6b3fb1645b1771c114 to your computer and use it in GitHub Desktop.
Save fchevitarese/ef6b3fb1645b1771c114 to your computer and use it in GitHub Desktop.
Values
data.forEach(function (harvest) {
var values = harvest.values,
h = new Harvest();
h.id = harvest.id;
h.uuid = harvest.uuid;
h.device = harvest.device;
h.date = harvest.created;
h.values = [];
values.forEach(function (value) {
var v = new Value(value);
v.datadoc = JSON.parse(value.datadoc);
h.values.push(v);
});
harvests.push(h);
});
@samirbr
Copy link

samirbr commented Jul 30, 2015

var dd = JSON.parse(value.datadoc);
v.datadoc = Object.keys(dd).reduce(function (arr, key) { 
    var value;
    if (typeof dd[key] === 'object') {
        value = Object.keys(dd[key]).reduce(function (a, k) {
             return a.concat([ dd[key][k] ]);
        }, []);
    } else {
        value = [ dd[key] ];
    }

    return arr.concat(value);
}, []).join(',');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment