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.
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.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 akey
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 containkey
as a property.object[key]
is used for comparison, butobject
is returned in the results.Additional tests added for this functionality