Skip to content

Instantly share code, notes, and snippets.

@ferreiro
Last active September 23, 2021 20:45
Show Gist options
  • Save ferreiro/792289572cfb9e354fd508866b28e3f2 to your computer and use it in GitHub Desktop.
Save ferreiro/792289572cfb9e354fd508866b28e3f2 to your computer and use it in GitHub Desktop.
const countries = [
{
name: "Albania",
local_calls: '€2323'
/// resto de propiedades...
},
{
name: "Zamora",
local_calls: '€2323'
/// resto de propiedades...
},
{
name: "Leganes",
local_calls: '€2323'
/// resto de propiedades...
},
];
const replaceCurrency = (valueWithCurrency) => {
const [_, value] = valueWithCurrency.split("€");
return `${value}€`;
};
const transformCountryCurrencies = (country) => ({
...country,
local_calls: replaceCurrency(country.local_calls),
// y aqui pones el resto de proppiedades que quieres normalizar
});
const sortDescending = (a, b) => {
if (a.name < b.name) {
return -1;
}
if (a.name > b.name) {
return 1;
}
return 0;
};
countries.sort(sortDescending).map(transformCountryCurrencies);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment