-1
props
という配列があり、オブジェクトを持つ配列の数がn
であり、すべての配列に異なる数のオブジェクトを含めることができます。
1)検索:私は2つの目標を持ってオブジェクトのn個の配列の間に相違点を見つける
... participation_enabled
、name
、pathing_enabled
、id
これらの特性は、同じプロパティIDの他の配列において異なる値を有することができる。
各オブジェクトは4つの特性を有しますオブジェクトの他の配列とは異なるすべてのオブジェクトプロパティをdiffsという別の配列に格納します。
2)他の配列(一意のid
)には見つからない余分なオブジェクトをすべて見つけ、extraという別の配列に格納します。
私のコードが正常に差異を返しますが、それはすべての余分なオブジェクトを返しません...
例:
[
[
{participation_enabled:"false", name:"PropEins", pathing_enabled:"true", id:"prop1"},
{participation_enabled:"false", name:"User Status", pathing_enabled:"false", id:"prop2"},
{participation_enabled:"false", name:"Initial ID", pathing_enabled:"false", id:"prop3"},
{participation_enabled:"false", name:"User ID", pathing_enabled:"false", id:"prop4"},
{participation_enabled:"false", name:"Subdomain3", pathing_enabled:"false", id:"prop20"},
{participation_enabled:"false", name:"Subdomain4", pathing_enabled:"false", id:"prop21"},
{participation_enabled:"false", name:"Subdomain5", pathing_enabled:"false", id:"prop22"}
],
[
{participation_enabled:"false", name:"PropEins", pathing_enabled:"false", id:"prop1"},
{participation_enabled:"false", name:"Room", pathing_enabled:"false", id:"prop2"},
{participation_enabled:"false", name:"Subdomain", pathing_enabled:"false", id:"prop70"}
],
[
{participation_enabled:"true", name:"PropEins", pathing_enabled:"true", id:"prop1"},
{participation_enabled:"true", name:"User Status", pathing_enabled:"true", id:"prop2"},
{participation_enabled:"true", name:"Trackingcode", pathing_enabled:"true", id:"prop3"},
{participation_enabled:"false", name:"User ID", pathing_enabled:"true", id:"prop4"},
{participation_enabled:"false", name:"User ID2", pathing_enabled:"false", id:"prop50"}
]
]
diffs
配列が含まれている必要があります。この例:
[
{id:"prop1", participation_enabled:["false","true"], pathing_enabled:["false","true"], index:0},
{id:"prop2", participation_enabled:["false","true"], name:["User Status","Room"], participation_enabled:["false","true"], pathing_enabled:["false","true"], index:1},
{id:"prop3", participation_enabled:["false","true"], name:["Initial ID","Trackingcode"], participation_enabled:["false","true"], pathing_enabled:["false","true"], index:2},
{id:"prop4", pathing_enabled:["false","true"], index:3}
]
extra
の配列は、
これは私のコードです:
var diff = {};
var extra = [];
props.forEach(function(val, i){
if (i == 0) {
val.forEach(function(v1, ind){
diff[v1.id] = {};
diff[v1.id].index = [ind];
for (var key in v1) {
diff[v1.id][key] = [v1[key]];
}
});
}
else {
val.forEach(function(v1){
var id = v1.id;
for (var key in v1) {
if(diff[id]) {
diff[id][key].push(v1[key]);
}
}
if(!diff[id]) {
extra.push(v1);
}
});
}
});
for (var key in diff) {
var nested = diff[key];
var index = nested.index.pop();
for (nestedKey in nested) {
nested[nestedKey] = underscoreGS._filter(nested[nestedKey], function(item, pos) {
return nested[nestedKey].indexOf(item) == pos;
});
if (nested[nestedKey].length < 2) {delete nested[nestedKey];}
}
diff[key].id = key;
diff[key].index = index
if (underscoreGS._keys(diff[key]).length < 3) {delete diff[key];}
}
diff = underscoreGS._values(diff);
return [diff, extra];
のためにその負の投票とは何ですか? – Valip