function prepareMerge(emails = {}) {
        const getContactToUpdate = (selected = []) => {
            // When there are less than 2 selected contacts, don't update or merge any contact.
            if (selected.length <= 1) {
                return;
            }

            /*
                Merge the vCards together, and create the update contact in the way the API expects.
                The first selected contact is the one that will be updated.
                Set the ID on the "new" contact (the one to update).
             */
            return {
                ...contactSchema.prepareContact(getMergedContact(selected)),
                ID: selected[0].id
            };
        };

        /*
            Contacts to remove are the selected contacts
            (except the first one, because it is the target for the merge)
            + the contacts selected for deletion.
         */
        const getContactsToRemove = (selected = [], deleted = []) =>
            selected
                .slice(1)
                .concat(deleted)
                .map(({ id }) => id);

        return Object.keys(emails).reduce((acc, key) => {
            const { selected, deleted } = emails[key];
            acc[key] = {
                update: getContactToUpdate(selected),
                remove: getContactsToRemove(selected, deleted)
            };
            return acc;
        }, {});
    }
/**
     * Get the contacts to update and delete from the grouping in the way that the API expects.
     * @param emails
     * @returns {object}
     */
Get the contacts to update and delete from the grouping in the way that the API expects.
@param emails
@returns {object}
Get the contacts to update and delete from the grouping in the way that the API expects . @param emails @returns { object }
function prepareMerge(emails = {}) {
        const getContactToUpdate = (selected = []) => {
            if (selected.length <= 1) {
                return;
            }
            return {
                ...contactSchema.prepareContact(getMergedContact(selected)),
                ID: selected[0].id
            };
        };
        const getContactsToRemove = (selected = [], deleted = []) =>
            selected
                .slice(1)
                .concat(deleted)
                .map(({ id }) => id);
        return Object.keys(emails).reduce((acc, key) => {
            const { selected, deleted } = emails[key];
            acc[key] = {
                update: getContactToUpdate(selected),
                remove: getContactsToRemove(selected, deleted)
            };
            return acc;
        }, {});
    }
function prepareMerge ( emails = { } ) { const getContactToUpdate = ( selected = [ ] ) => { if ( selected . length <= 1 ) { return ; } return { ... contactSchema . prepareContact ( getMergedContact ( selected ) ) , ID : selected [ 0 ] . id } ; } ; const getContactsToRemove = ( selected = [ ] , deleted = [ ] ) => selected . slice ( 1 ) . concat ( deleted ) . map ( ( { id } ) => id ) ; return Object . keys ( emails ) . reduce ( ( acc , key ) => { const { selected , deleted } = emails [ key ] ; acc [ key ] = { update : getContactToUpdate ( selected ) , remove : getContactsToRemove ( selected , deleted ) } ; return acc ; } , { } ) ; }
Get the contacts to update and delete from the grouping in the way that the API expects.
Get the contacts to update and delete from the grouping in the way that the API expects .
// When there are less than 2 selected contacts, don't update or merge any contact. /*
                Merge the vCards together, and create the update contact in the way the API expects.
                The first selected contact is the one that will be updated.
                Set the ID on the "new" contact (the one to update).
             */ /*
            Contacts to remove are the selected contacts
            (except the first one, because it is the target for the merge)
            + the contacts selected for deletion.
         */