Skip to content

Instantly share code, notes, and snippets.

@iamdey
Created September 7, 2017 08:16
Show Gist options
  • Save iamdey/1d47376665684f10cbcc92839a99c27e to your computer and use it in GitHub Desktop.
Save iamdey/1d47376665684f10cbcc92839a99c27e to your computer and use it in GitHub Desktop.
Caliopen favorite address
favoriteAddressFilter = (addresses, searchTerms) => addresses.reduce((acc, address) => {
if (!acc) {
return address;
}
if (address.startsWith(searchTerms) && !acc.startsWith(searchTerms)) {
return address;
}
if (!acc.is_primary && address.is_primary === true) {
return address;
}
return acc;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment