Skip to content

Instantly share code, notes, and snippets.

@jukbot jukbot/temp data
Last active Nov 13, 2017

Embed
What would you like to do?
result = [
{
"job_cycle": [
3,
7,
8
],
"job_setup": [
5,
5,
5
],
"job_workload": [
6,
28,
3
],
"job_duration": [
6,
9.333333333333334,
4
],
"job_machine": [
1,
2,
1
],
"job_station": [
1,
2,
4
],
"job_part": "X4",
"job_sku": "94000",
"job_weight": [
0.3,
0.5,
0.2
],
"order_process": [
1,
2,
4
],
"start": 1513126800,
"end": 15131268006,
"order_color": "#0f6a1c",
"order_product": "iPhone X",
"order_quantity": 2
},
{
"job_cycle": [
7,
7,
7
],
"job_setup": [
5,
5,
9
],
"job_workload": [
14,
28
],
"job_duration": [
14,
9.333333333333334,
3
],
"job_machine": [
3,
2,
2
],
"job_station": [
1,
2,
4
],
"job_part": "I2",
"job_sku": "4200",
"job_weight": [
0.7,
0.5,
3
],
"order_process": [
1,
2,
4
],
"start": 1513126800,
"end": 151312680014,
"order_color": "#b90a05",
"order_product": "I",
"order_quantity": 4
}
]
let splitArr = result.map((data) => _.transform(data, function (result, value, key) {
if (!_.isArray(value)) return;
if (result.length < value.length) {
result.push(..._.times(value.length - result.length, () => _.clone(
data)))
}
value.map((ele, index) => result[index][key] = ele)
}, []))
// let splitArr = result.map((data) => (_.mapValues(data, (val) => _.isArray(val) ? val[0] : val)))
console.log(splitArr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.