-1
i have the following data:
[
{
"titulo": "Livro",
"descricao": "descricao do livro 1",
"info": [
{
"nome": "nome do livro 1",
"paginas": 223,
"lido": true,
}
],
},
{
"titulo": "Trilogia 1",
"descricao": "descricao da trilogia 1",
"info": [
{
"nome": "livro 1"
"paginas": 219,
"lido": true,
},
{
"nome": "livro 2"
"paginas": 242,
"lido": false,
},
{
"nome": "livro 3"
"paginas": 331,
"lido": false,
}
],
}
]
What I’m trying to do and I couldn’t do is: sort the titles according to the book read, if any book info has read === false, this unread book has to be at the top, so in this case, the Book has to come last and to Trilogy first, because she has false information in info, and in info sort tbm in the same way, the objects of read == false always at the top
I tried to use reduce, map + filter but could not get a result of type, this part of sort so specifically confused me
Why did you use
map
andfilter
? These functions do not do this. The correct function issort
, and this allows you to use callback.– Wallace Maxters
is that in case I needed to iterate through the array info of each object to find if it exists read === false and sort to the top of the list
– i'ts me
please include your code that you attempt to sort. I also recommend that you read the manual on how NOT to ask questions, especially the section Thinking we’ll do all your work for free
– Pedro Sanção