I have a complicated problem we need to solve.
I have an array which looks like this:
var array = [
["1hszZhsez7", 0, "mb12", 0],
["87hJKLi893", 1, "tt43", 0],
["jchd79dcic", 1, "tt43", 2],
["as0w9ejasm", 1, "tt43", 1],
["coosihchw9", 0, "zz00", 0],
["vs0x0j9ndm", 1, "uu33", 0],
["00s0kd20r7", 1, "uu33", 2],
["xassdwddao", 1, "uu33", 1],
["caosw8ncxc", 2, "uu33", 0]
];
This array always has different values. So let's get in.
The array has basically this values:
var array = [
[id, type, code, priority]
];
id: The id is unique. Nothing special.
type: There are three different types. 0, 1 and 2.
code: The code is NOT unique. It can be the same for multiple array items.
priority: The priority is a number. If the number is low, the priority is high. If the number is large, priority is low.
The task:
First, we need to sort the different types into different arrays. So that it looks like this:
var type_zero = [
["coosihchw9", 0, "zz00", 0]
];
var type_one = [
["87hJKLi893", 1, "tt43", 0],
["jchd79dcic", 1, "tt43", 2],
["as0w9ejasm", 1, "tt43", 1],
["vs0x0j9ndm", 1, "uu33", 0],
["00s0kd20r7", 1, "uu33", 2],
["xassdwddao", 1, "uu33", 1]
];
var type_two = [
["caosw8ncxc", 2, "uu33", 0]
];
That's easy with this function:
array.forEach(function(item) {
if (item[1] === 0) {
type_zero.push([item[0], item[1], item[2], item[3], item[4], item[5]]);
}
else if (item[1] === 1) {
type_one.push([item[0], item[1], item[2], item[3], item[4], item[5]]);
}
else if (item[1] === 2) {
type_two.push([item[0], item[1], item[2], item[3], item[4], item[5]]);
}
});
But then the headache starts. We need to make a separate array for every code group. But we never know how much different codes there are. So we can not make static arrays.
Whatever which code we use. In the end, it should look like this, based on our example array.
var type_zero_zz00 = [
["coosihchw9", 0, "zz00", 0]
];
var type_one_tt43 = [
["87hJKLi893", 1, "tt43", 0],
["jchd79dcic", 1, "tt43", 2],
["as0w9ejasm", 1, "tt43", 1],
];
var type_one_uu33 = [
["vs0x0j9ndm", 1, "uu33", 0],
["00s0kd20r7", 1, "uu33", 2],
["xassdwddao", 1, "uu33", 1]
];
var type_two_uu33 = [
["caosw8ncxc", 2, "uu33", 0]
];
Why I need these arrays? In the next step, I have to do a forEach loop for every array list to proceed. I hope someone knows a solution because this problem killed many days and the thoughts at the impossibility are going bigger.
Thanks in advance,
Marius