Filter | const newAttachments = [
{
"id": "658b92bbdad4a0e81cce4b68",
"url": "http://localhost:10000/devstoreaccount1/actiontracker-dev/5b3494dc-dcad-4d56-895b-1e0f0639b384.txt",
"name": "5b3494dc-dcad-4d56-895b-1e0f0639b384.txt",
"mimeType": "image/png",
"originalName": "30MB.txt",
"size": 30096000,
"owner": "me"
},
{
"id": "658b9354ab8ade0e3ad79ff0",
"url": "http://localhost:10000/devstoreaccount1/actiontracker-dev/f7c81f08-5fe4-4025-a787-f2e27950cf53.txt",
"name": "f7c81f08-5fe4-4025-a787-f2e27950cf53.txt",
"mimeType": "image/png",
"originalName": "30MB.txt",
"size": 30096000,
"owner": "me"
}
]
const oldAttachments = [
{
"id": "658a94b79a2082b86b6b55d5",
"url": "http://localhost:10000/devstoreaccount1/actiontracker-dev/83ede44f-6ff9-445f-aceb-3cb911d6d234.png",
"name": "83ede44f-6ff9-445f-aceb-3cb911d6d234.png",
"mimeType": "image/png",
"originalName": "Riotinto.png",
"size": 943,
"owner": "me"
},
{
"id": "658b92bbdad4a0e81cce4b68",
"url": "http://localhost:10000/devstoreaccount1/actiontracker-dev/5b3494dc-dcad-4d56-895b-1e0f0639b384.txt",
"name": "5b3494dc-dcad-4d56-895b-1e0f0639b384.txt",
"mimeType": "image/png",
"originalName": "30MB.txt",
"size": 30096000,
"owner": "me"
},
{
"id": "658b9354ab8ade0e3ad79ff0",
"url": "http://localhost:10000/devstoreaccount1/actiontracker-dev/f7c81f08-5fe4-4025-a787-f2e27950cf53.txt",
"name": "f7c81f08-5fe4-4025-a787-f2e27950cf53.txt",
"mimeType": "image/png",
"originalName": "30MB.txt",
"size": 30096000,
"owner": "me"
}
]
const determineDeletedAttachmentIdsByFilter = (oldAttachments, newAttachments) => {
const newAttachmentIds = oldAttachments.filter((oldAttch) => {
return !newAttachments.some((newAttch) => newAttch.id === oldAttch.id);
}).map((val) => val.id);
return newAttachmentIds;
};
const result = determineDeletedAttachmentIdsByFilter(
oldAttachments,
newAttachments
)
console.log(result)
| ready |
Map | const newAttachments = [
{
"id": "658b92bbdad4a0e81cce4b68",
"url": "http://localhost:10000/devstoreaccount1/actiontracker-dev/5b3494dc-dcad-4d56-895b-1e0f0639b384.txt",
"name": "5b3494dc-dcad-4d56-895b-1e0f0639b384.txt",
"mimeType": "image/png",
"originalName": "30MB.txt",
"size": 30096000,
"owner": "me"
},
{
"id": "658b9354ab8ade0e3ad79ff0",
"url": "http://localhost:10000/devstoreaccount1/actiontracker-dev/f7c81f08-5fe4-4025-a787-f2e27950cf53.txt",
"name": "f7c81f08-5fe4-4025-a787-f2e27950cf53.txt",
"mimeType": "image/png",
"originalName": "30MB.txt",
"size": 30096000,
"owner": "me"
}
]
const oldAttachments = [
{
"id": "658a94b79a2082b86b6b55d5",
"url": "http://localhost:10000/devstoreaccount1/actiontracker-dev/83ede44f-6ff9-445f-aceb-3cb911d6d234.png",
"name": "83ede44f-6ff9-445f-aceb-3cb911d6d234.png",
"mimeType": "image/png",
"originalName": "Riotinto.png",
"size": 943,
"owner": "me"
},
{
"id": "658b92bbdad4a0e81cce4b68",
"url": "http://localhost:10000/devstoreaccount1/actiontracker-dev/5b3494dc-dcad-4d56-895b-1e0f0639b384.txt",
"name": "5b3494dc-dcad-4d56-895b-1e0f0639b384.txt",
"mimeType": "image/png",
"originalName": "30MB.txt",
"size": 30096000,
"owner": "me"
},
{
"id": "658b9354ab8ade0e3ad79ff0",
"url": "http://localhost:10000/devstoreaccount1/actiontracker-dev/f7c81f08-5fe4-4025-a787-f2e27950cf53.txt",
"name": "f7c81f08-5fe4-4025-a787-f2e27950cf53.txt",
"mimeType": "image/png",
"originalName": "30MB.txt",
"size": 30096000,
"owner": "me"
}
]
const determineDeletedAttachmentIdsByMapping = (oldAttachments, newAttachments) => {
const oldAttachmentIds = oldAttachments.map((val, ind, arr) => {
return val.id;
});
const newAttachmentIds = newAttachments.map((val, ind, arr) => {
return val.id;
});
const deletedAttachmentIds = oldAttachmentIds.filter((val, ind, arr) => {
if (!newAttachmentIds.includes(val)) {
return val;
}
});
return deletedAttachmentIds;
};
const result = determineDeletedAttachmentIdsByMapping(
oldAttachments,
newAttachments
)
console.log(result)
| ready |