I’m trying to reduce the following data from video info into a custom Object structure that removes "label" keys duplicates but also keeps true all the encountered features that are available.
The initial data looks like this:
[
{
"label": "4320p",
"features": {
"HDR": false,
"60fps": true
}
},
{
"label": "2160p",
"features": {
"HDR": false,
"60fps": true
}
},
{
"label": "2160p",
"features": {
"HDR": true,
"60fps": true
}
},
{
"label": "1440p",
"features": {
"HDR": false,
"60fps": true
}
},
{
"label": "1440p",
"features": {
"HDR": true,
"60fps": true
}
},
{
"label": "1080p",
"features": {
"HDR": false,
"60fps": true
}
},
{
"label": "1080p",
"features": {
"HDR": true,
"60fps": true
}
},
{
"label": "1080p",
"features": {
"HDR": false,
"60fps": true
}
},
{
"label": "1080p",
"features": {
"HDR": true,
"60fps": true
}
},
{
"label": "720p",
"features": {
"HDR": false,
"60fps": true
}
},
{
"label": "720p",
"features": {
"HDR": true,
"60fps": true
}
},
{
"label": "720p",
"features": {
"HDR": false,
"60fps": true
}
},
{
"label": "720p",
"features": {
"HDR": false,
"60fps": false
}
},
{
"label": "720p",
"features": {
"HDR": true,
"60fps": true
}
},
{
"label": "720p",
"features": {
"HDR": false,
"60fps": false
}
},
{
"label": "480p",
"features": {
"HDR": true,
"60fps": true
}
},
{
"label": "480p",
"features": {
"HDR": false,
"60fps": false
}
},
{
"label": "480p",
"features": {
"HDR": false,
"60fps": false
}
},
{
"label": "480p",
"features": {
"HDR": true,
"60fps": false
}
},
{
"label": "360p",
"features": {
"HDR": true,
"60fps": true
}
},
{
"label": "360p",
"features": {
"HDR": false,
"60fps": false
}
},
{
"label": "360p",
"features": {
"HDR": false,
"60fps": false
}
},
{
"label": "360p",
"features": {
"HDR": true,
"60fps": false
}
},
{
"label": "240p",
"features": {
"HDR": true,
"60fps": true
}
},
{
"label": "240p",
"features": {
"HDR": false,
"60fps": false
}
},
{
"label": "240p",
"features": {
"HDR": false,
"60fps": false
}
},
{
"label": "240p",
"features": {
"HDR": true,
"60fps": false
}
},
{
"label": "144p",
"features": {
"HDR": true,
"60fps": true
}
},
{
"label": "144p",
"features": {
"HDR": false,
"60fps": false
}
},
{
"label": "144p",
"features": {
"HDR": false,
"60fps": false
}
},
{
"label": "144p",
"features": {
"HDR": true,
"60fps": false
}
}
]
As you can see there are many Objects for a single resolution label but some of them have HDR while others have 60fps while other might have none of them or just both.
What I’m trying to do is to reduce this array with the following reduce function.
Assuming that resolutions
is the above Object:
resolutions.reduce((unique, o) => {
if (!unique.some((obj) => obj.label === o.label)) {
unique.push(o);
}
return unique;
}, []);
That gives me the following structure:
[
{
"label": "4320p",
"features": {
"HDR": false,
"60fps": true
}
},
{
"label": "2160p",
"features": {
"HDR": false,
"60fps": true
}
},
{
"label": "1440p",
"features": {
"HDR": false,
"60fps": true
}
},
{
"label": "1080p",
"features": {
"HDR": false,
"60fps": true
}
},
{
"label": "720p",
"features": {
"HDR": false,
"60fps": true
}
},
{
"label": "480p",
"features": {
"HDR": true,
"60fps": true
}
},
{
"label": "360p",
"features": {
"HDR": true,
"60fps": true
}
},
{
"label": "240p",
"features": {
"HDR": true,
"60fps": true
}
},
{
"label": "144p",
"features": {
"HDR": true,
"60fps": true
}
}
]
But if you look closer you’ll see that during the reduce operation some booleans are merged with the first element value for each unique label key and I need to have in the end the true feature enabled even if just one of them was true.
The 2160p
label is a good example where there actually is an object that has HDR: true
but in the end I just get it as false
Do you have any idea on how to manage this situation with modern JavaScript?
stromectol for head lice – ivermectin 6mg online stromectol oral
furosemide 20 mg brand name – can you buy furosemide otc pharmacy furosemide 25 mg
how to buy cialis in canada – modafinil online pharmacy buy cialis australia paypal
stromectol medication – buy stromectol pills ivermectin for human
betfair casino online – online casino real money usa red dog casino
best pills for ed – erectile dysfunction pills new ed drugs
prednisone sale – prednisone on line how to get prednisone online
where to buy female viagra in us – buy viagra online cheap sildenafil 48 tabs 50 mg price
cialis prescription online canada – Cialis pharmacy buy cialis online nz
ivermectin 200 mcg – ivermectin uk buy ivermectin canada
ed drugs compared – ed drugs online what is erectile dysfunction
doxycycline order canada – how to get doxycycline can you buy doxycycline
buy generic accutane 40 mg – how to buy accutane online accutane generic
orlistat medication effectiveness – orlistat emc xenical 84 cap 120mg
539186 596376I got what you intend, saved to favorites , extremely decent internet website . 273464
cheap cialis online canada – cialis non prescription order cialis generic
stromectol uk buy – stromectol for humans for sale ivermectin 12 mg tablet
accutane medicine buy – isotretinoin for acne ipledge accutane
empire city casino online – casinos ocean casino online
order viagra – cialis tablets order tadalafil 5mg generic
acheter 25mg gГ©nГ©rique viagra en france – sildenafil generique en pharmacie acheter 20mg tadalafil en ligne
buy prednisone generic – prednisone 5mg drug prednisone 40mg ca
oral accutane 40mg – order accutane 10mg for sale cheap amoxicillin pills
tadalafil generic buy cialis
tizanidine order – colchicine 0.5mg usa buy gloperba pills
tadalafil drug https://cialismat.com/
tadalafil price walmart buy generic cialis online with mastercard
tadalafil cost walmart tadalafil online with out prescription
tadalafil online cost tadalafil generic
tadalafil liquid tadalafil blood pressure
buy tadalis https://nextadalafil.com/
lowest price cialis tadalafil liquid
where to buy tadalafil on line tadalafil cost walmart
order ivermectin online ivermectin from canada
209644 501881Admiring the time and energy you put into your blog and in depth information you offer. It is very good to come across a blog every once in a although that isnt the same old rehashed material. Amazing read! Ive bookmarked your web site and Im adding your RSS feeds to my Google account. 141968