Last active
September 23, 2021 20:45
-
-
Save ferreiro/792289572cfb9e354fd508866b28e3f2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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