simplify adding common countries to top of list

This commit is contained in:
Ben Wheeler 2019-08-06 20:42:03 -04:00
parent 564baf2ebc
commit 167a70f437

View file

@ -1052,13 +1052,10 @@ module.exports.lookupCountryInfo = countryCode => (
* @returns {array} revised array of country objects, with duplicates inserted at beginning
*/
const dupeCommonCountries = module.exports.dupeCommonCountries = (startingCountryInfo, commonCountryCodes) => {
const newCountryInfo = startingCountryInfo.map(item => ({...item}));
commonCountryCodes.reverse().forEach(commonCountryCode => {
const existing = newCountryInfo
.find(country => country.code === commonCountryCode.toLowerCase());
if (existing) newCountryInfo.unshift(existing);
});
return newCountryInfo;
const commonCountriesInfo = commonCountryCodes.map(commonCountryCode => (
startingCountryInfo.find(country => country.code === commonCountryCode.toLowerCase())
));
return [...commonCountriesInfo, ...startingCountryInfo];
};
/*