mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2025-02-17 00:21:20 -05:00
simplify adding common countries to top of list
This commit is contained in:
parent
564baf2ebc
commit
167a70f437
1 changed files with 4 additions and 7 deletions
|
@ -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];
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in a new issue