Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save juandaveth/6ddd4cdca56e6a8536bdaa22eb35c17a to your computer and use it in GitHub Desktop.
Save juandaveth/6ddd4cdca56e6a8536bdaa22eb35c17a to your computer and use it in GitHub Desktop.
newArray.forEach(element => {
const lineArray = element.split("/");
lineArray.forEach((code, index) => {
// Distrito code:
const first = code.split(" ");
// Distrito name, using function for cases with two words:
function add(isUndefined) {
return lineArray[2].split(" ")[3] || '';
}
listDistName = `${lineArray[2].split(" ")[2]} ${add(true)}`;
// Provincia code:
const lineProvCode = lineArray[1].split(" ")[1];
// Provincia name:
const lineProvName = lineArray[1].split(" ")[2];
if (index === 2) {
const obj = {
codigo: first[1],
listDistName,
lineProvCode,
lineProvName,
}
if (obj.codigo.length > 0) {
dist.push(obj);
}
}
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment