Skip to content

Instantly share code, notes, and snippets.

@damiancipolat
Created October 18, 2021 23:16
Show Gist options
  • Save damiancipolat/cb70076129afa37d0fb3391da92815b2 to your computer and use it in GitHub Desktop.
Save damiancipolat/cb70076129afa37d0fb3391da92815b2 to your computer and use it in GitHub Desktop.
En este ejercicio se debe borrarn de las listas vinculadas los valores que sean menores a 100 y retornarlo por consola.
const year = {
num: 2019,
month: {
num: 1,
avgDollarValue: 90,
month: {
num: 2,
avgDollarValue: 105,
month: {
num: 0,
month: null
}
}
},
year: {
num: 2020,
month: {
num: 1,
avgDollarValue: 95,
month: {
num: 2,
avgDollarValue: 160,
month: {
num: 3,
avgDollarValue: 165,
month: {
num: 0,
month: null
}
}
}
},
year: {
num: 0,
year: null
}
}
}
cont removeBellow=(head,value)=>{
let currentNode = head.month;
let previousNode;
while(currentNode.month) {
//Analiza si cumple y sino bypasea.
if (currentNode.avgDollarValue&&currentNode.avgDollarValue<value){
head.month = currentNode.month;
}
//Camina al proximo nodo.
previousNode = currentNode;
currentNode = currentNode.month;
}
};
const cleanList =(data)=>{
const cotization = 100;
//Si hay un mes limpio la cadena.
if (data.month){
removeBellow(data,cotization);
}
//Si hay un año limpio los meses del año.
if (data.year)
removeBellow(data.year,cotization);
}
cleanList(year);
console.log(JSON.stringify(year));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment