Skip to content
This repository has been archived by the owner on May 1, 2023. It is now read-only.

allow findBestMatch to accept an array of objects #124

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

chrissyast
Copy link

Use case:

Instead of wanting to compare ["foo","bar","baz"], it can be useful to pass in an array of objects for which you want to compare one property, i.e.

[
    { name: "foo", otherProperty: 23 },
    { name: "bar", otherProperty: 27 },
    { name: "baz", otherProperty: 99 }
]

and instruct the function to compare based on the name property, but return the whole object in the response.

Summary of changes:

findBestMatch now accepts a key argument. If this argument is not supplied, current behaviour will be retained (i.e. the array member will be used for comparison and must be a string). If a key is supplied, all members of that array must be objects which contain key as a property. object[key] is used for comparison, but object is returned in the results.

Additional tests added for this functionality

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant