Skip to content

Instantly share code, notes, and snippets.

@mdupless
Last active June 28, 2018 17:37
Show Gist options
  • Select an option

  • Save mdupless/4ec1019a2997e006b7d3cb8cd1fcc46f to your computer and use it in GitHub Desktop.

Select an option

Save mdupless/4ec1019a2997e006b7d3cb8cd1fcc46f to your computer and use it in GitHub Desktop.
Write a function to practice javascript server skills
/**
Merge user objects to provide a final single object for each user
(identity resolution)
We should merge two objects if they share any of the same 'primary' key. The
four possible primary keys are:
- zendesk_id
- email
- phone_number
- salesforce_id
For all other fields, a match on any other key does not indicate that the users should be merged
for example, users from the same city should not be merged
When merging, any conflicts can be resolved arbitrarily
for example, if two user objects are to be merged and one has key 'city' with value 'nyc' and
one has key 'city' with value 'brooklyn' you may select either as the key in the final object
ARGS:
existing_users - list of existing user objects, these are users already in
the system and their data
new_user_docs - list of new user objects from the most recent pull from the
helpdesk, these should be merged into the existing users OR merged with
other new user objects to form a new user object in the output
RETURNS:
final_user_docs - list of final user objects
Example 1 (simple):
args:
existing_user_objects = [{zendesk_id: 1, name: 'will'},
{zendesk_id: 2, name: 'bill'}]
new_user_objects = [{zendesk_id: 1, city: 'nyc'}]
returns:
final_user_objects = [{zendesk_id: 1, name: 'will', city: 'nyc'},
{zendesk_id: 2, name: 'bill'}]
Example 2 (more involved):
args:
existing_user_objects = [{zendesk_id: 1, name: 'bob'},
{email: 'e1', color: 'red'}]
new_user_objects = [{zendesk_id: 1, phone_number: 'p1', dog: 'max'},
{email: 'e1', phone_number: 'p1', cheese: 'stinky'}]
returns:
final_user_objects = [{zendesk_id: 1, email 'e1', phone_number: 'p1',
name: 'bob', color: 'red' ,dog: 'max',
cheese: 'stinky'}]
*/
module.exports = {
merge_user_ids: function(existing_users_objects, new_user_objects) {
return existing_users_objects;
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment