Created
October 18, 2021 23:16
-
-
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.
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 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&¤tNode.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