client/state/posts/utils.js
function applyMetadataEdit( metadata, edit ) {
	switch ( edit.operation ) {
		case 'update': {
			// Either update existing key's value or append a new one at the end
			const { key, value } = edit;
			if ( find( metadata, { key } ) ) {
				return map( metadata, m => ( m.key === key ? { key, value } : m ) );
			}
			return concat( metadata || [], { key, value } );
		}
		case 'delete': {
			// Remove a value from the metadata array. If the key is not present,
			// return unmodified original value.
			const { key } = edit;
			if ( find( metadata, { key } ) ) {
				return reject( metadata, { key } );
			}
			return metadata;
		}
	}

	return metadata;
}
function applyMetadataEdit( metadata, edit ) {
	switch ( edit.operation ) {
		case 'update': {
			// Either update existing key's value or append a new one at the end
			const { key, value } = edit;
			if ( find( metadata, { key } ) ) {
				return map( metadata, m => ( m.key === key ? { key, value } : m ) );
			}
			return concat( metadata || [], { key, value } );
		}
		case 'delete': {
			// Remove a value from the metadata array. If the key is not present,
			// return unmodified original value.
			const { key } = edit;
			if ( find( metadata, { key } ) ) {
				return reject( metadata, { key } );
			}
			return metadata;
		}
	}

	return metadata;
}
/*
Applies a metadata edit operation (either update or delete) to an existing array of
metadata values.