E
E
ennet2015-10-06 11:15:44
JavaScript
ennet, 2015-10-06 11:15:44

How to glue an array correctly?

There is an array like:

var data = [{"time":["00:00"],"workstation":4,"worker":4}, {"time":["00:00","01:45","03:30","05:15","07:00","08:45","10:30","12:15","14:00"],"workstation":11,"worker":4},{"time":["02:40"],"workstation":14,"worker":1},{"time":["02:40"],"workstation":4,"worker":1},{"time":["17:30","19:15","21:00","22:45"],"workstation":4,"worker":1},{"time":["17:30","19:15","21:00","22:45"],"workstation":14,"worker":1}];

The time is stored in a timestamp. To simplify, I did it in a normal format for the time being. Here is the original array jsfiddle.net/p2exsn36/1
That is, each element is an object of the form
{
  "time" : [],
  "workstation" : 14,
  "worker" : 1  		
}

In this object in the time array there are duplicates of the time, also the worker can be different and workstation.
At the output, I would like to get a "clean" array of the form:
[
{"time" : "00:00", "workstation" : [14,5], "worker" : [1,4]}, 
{"time" : "01:45", "workstation" : [11], "worker" : [4]}
]

Can you please tell me how to glue them correctly? Thank you! Just starting to learn javascript

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Marcuzy, 2015-10-06
@ennet

As far as I understand your task, you can do this jsfiddle.net/marcuzy/p2exsn36/2
Using objects instead of arrays, you can simplify and speed up the algorithm. If edge needs an array, just convert it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question