Javascript:
function array_diff_key( object ) { // Computes the difference of arrays using keys for comparison
//
// + original by: Ates Goral (http://magnetiq.com)
var tpm_ar = new Object(), argc = arguments.length, argv = arguments, key, argidx, other;
for (key in object) {
tpm_ar[key] = object[key];
}
for (argidx = 1; argidx < argc; ++argidx) {
other = argv[argidx];
if (other instanceof Object) {
for (key in other) {
delete tpm_ar[key];
}
}
}
return tpm_ar;
}
Примеры:
array_diff_key({red: 1, green: 2, blue: 3, white: 4});
{"red":1, "green":2, "blue":3, "white":4}
array_diff_key({red: 1, green: 2, blue: 3, white: 4}, {red: 5});
{"green":2, "blue":3, "white":4}
array_diff_key({red: 1, green: 2, blue: 3, white: 4}, {red: 5}, {green: 6, blue: 7});
{"white":4}
array_diff_key({red: 1, green: 2, blue: 3, white: 4}, {red: 5}, {red: 5});
{"green":2, "blue":3, "white":4}
|
Roxa wieliczka
Отправить комментарий
Приветствуются комментарии:Для остальных вопросов и обсуждений есть форум.