Похожие чаты

Please I am trying to sort an array of nested

arrays. I tried sorting out items in array according to date and mapping the data but I'm facing issues. Any assistance?

8 ответов

3 просмотра

Code??

Your question is lacking. Please include: - What you have - What you want - What you have tried - The results of what you tried - Any error messages For example: "I have the string "52 854". I want it as the number 52854. I tried using Number("52 854"), but it just becomes NaN. I also tried Number.parseInt("52 854"), but it became just 52. What am I doing wrong?" For a more detailed guide, see StackOverflow's guide to asking

generally, nestedArr.sort(subArr => Math.max(...subArr.map(_ => _.date)))

something like nestedArr.sort((a, b) => Math.max(...a.map(_ => _.date)) > Math.max(...b.map(_ => _.date)) ? -1 : 1)

Bt-Baw Автор вопроса

{ "products": [ { "id": 1, "name": "Product 1", "prices": [ { "id": 1, "price": 46, "date": "2019-01-01T17:16:32+00:00" }, { "id": 2, "price": 34, "date": "2018-11-01T17:16:32+00:00" } ] }, { "id": 2, "name": "Product 2", "prices": [ { "id": 3, "price": 45, "date": "2019-01-01T17:16:32+00:00" }, { "id": 4, "price": 56, "date": "2018-11-01T17:16:32+00:00" } ] }, { "id": 3, "name": "Product 3", "prices": [ { "id": 5, "price": 56, "date": "2017-01-01T17:16:32+00:00" }, { "id": 6, "price": 46, "date": "2018-11-01T17:16:32+00:00" } ] } ] }

Bt-Baw Автор вопроса
Simen
Your question is lacking. Please include: - What y...

{ "products": [ { "id": 1, "name": "Product 1", "prices": [ { "id": 1, "price": 46, "date": "2019-01-01T17:16:32+00:00" }, { "id": 2, "price": 34, "date": "2018-11-01T17:16:32+00:00" } ] }, { "id": 2, "name": "Product 2", "prices": [ { "id": 3, "price": 45, "date": "2019-01-01T17:16:32+00:00" }, { "id": 4, "price": 56, "date": "2018-11-01T17:16:32+00:00" } ] }, { "id": 3, "name": "Product 3", "prices": [ { "id": 5, "price": 56, "date": "2017-01-01T17:16:32+00:00" }, { "id": 6, "price": 46, "date": "2018-11-01T17:16:32+00:00" } ] } ] } So I have this array of products and I have mapped the data, but I want the key prices to return the sorted array of prices in order of recent date

Bt-Baw Автор вопроса
Bt Baw
{ "products": [ { "id":...

Hope you get it now @Suppen

Bt-Baw Автор вопроса

Похожие вопросы

Обсуждают сегодня

Ясн. Но я всеравно к кедам отношусь с опасением. Чисто субьективное кедосозерцание. Что касаемо "восторга изяшности кед" так и не вкурил, хотя много слышал, пока не поставил с...
Артем Записной
30
Такой вопросец - есть функция function MySuperDuperConcat(const a: array of AnsiString): AnsiString; Как мне в её теле сделать вот так? Result:=Concat(a); А не грустный вариан...
notme
15
Есть какой-нибудь для Delphi/FPC T*Compression(Decompression)Stream на базе LZ4/Zstd/любой другой быстрый(и хорошо сжимающий) алгоритм А ещё лучше в pure pascal А ещё лучше од...
notme
48
type TObj = object procedure Init; virtual; end; TObj1 = object(TObj) procedure Init; override; end; procedure TObj1.Init; begin inherited; end; procedur...
Alexander 👋
29
They keep hyping $FUN but where's the progress? 🙄
Noah Noure
23
Btw guys very stupid question but i haven't researchd so js asking you pros . Can ltc be traced too? Literally point to pint to the user? And getting the banks blocked ? Exch...
20
А чем вам питонисты не угодили?😂
.
79
Hey guys, did you see the new announcement about $Fun? 🔥
Filip Murphy
55
How can a minority hashrate chain defend from a fork-hopping ASIC miner? The problem: 1. A miner comes into your network, and mines at 60-70% hashrate. 2. After some time, th...
Kishniev
13
yeap, thanks guys for response, but I really like to understand does a pool created on curve.fi has the option or api or I can call a function of a smart contract to set excha...
Oleg Karoza
11
Карта сайта