Retrieving value from two arrays - javascript

I have two arrays.
STUD = [{"id":1,"name":"Kida"},{"id":2,"name":"Kidb"},{"id":3,"name":"Kidc"},{"id":4,"name":"Kidd"},{"id":5,"name":"Kide"}]
IDCRD = [{"id":3,"status":"Y"},{"id":4,"status":"Y"},{"id":2,"status":"N"},{"id":5,"status":"Y"},{"id":1,"status":"N"}]
Then I have a loop:
for(var i=0;i<STUD.length;i++){
var id = STUD[i][0];
var name = STUD[i][1];
var status = ?
}
I need the status for STUD[i] from IDCRD array having the same ID inside this loop.

Have another loop on IDCRD and match ids of STUD and IDCRD then get the status
STUD = [{
"id": 1,
"name": "Kida"
}, {
"id": 2,
"name": "Kidb"
}, {
"id": 3,
"name": "Kidc"
}, {
"id": 4,
"name": "Kidd"
}, {
"id": 5,
"name": "Kide"
}];
IDCRD = [{
"id": 3,
"status": "Y"
}, {
"id": 4,
"status": "Y"
}, {
"id": 2,
"status": "N"
}, {
"id": 5,
"status": "Y"
}, {
"id": 1,
"status": "N"
}];
for (var i = 0; i < STUD.length; i++) {
var id = STUD[i].id;
var name = STUD[i].name;
for (j = 0; j < IDCRD.length; j++) {
if (STUD[i].id == IDCRD[j].id) {
var status = IDCRD[j].status;
}
}
console.log(id, name, status);
}

The function status should do what you need
var STUD = [{"id":1,"name":"Kida"},{"id":2,"name":"Kidb"},{"id":3,"name":"Kidc"},{"id":4,"name":"Kidd"},{"id":5,"name":"Kide"}];
var IDCRD = [{"id":3,"status":"Y"},{"id":4,"status":"Y"},{"id":2,"status":"N"},{"id":5,"status":"Y"},{"id":1,"status":"N"}];
function status(i){ return IDCRD.filter(w => w.id == STUD[i].id)[0].status }
console.log(status(0));
console.log(status(1));
console.log(status(2));
console.log(status(3));
console.log(status(4));
or if you run with Node you can write
status = i => IDCRD.filter(w => w.id == STUD[i].id)[0].status

You could take a Map and use id as key and take the map for an easy access to the data of IDCRD.
var stud = [{ id: 1, name: "Kida" }, { id: 2, name: "Kidb" }, { id: 3, name: "Kidc" }, { id: 4, name: "Kidd" }, { id: 5, name: "Kide" }],
IDCRD = [{ id: 3, status: "Y" }, { id: 4, status: "Y" }, { id: 2, status: "N" }, { id: 5, status: "Y" }, { id: 1, status: "N" }],
map = IDCRD.reduce((m, o) => m.set(o.id, o), new Map),
result = stud.map(o => Object.assign({}, o, map.get(o.id)));
console.log(result);
.as-console-wrapper { max-height: 100% !important; top: 0; }
Another solution could be using Array#find, but this approach iterates the array for each item to find.
var stud = [{ id: 1, name: "Kida" }, { id: 2, name: "Kidb" }, { id: 3, name: "Kidc" }, { id: 4, name: "Kidd" }, { id: 5, name: "Kide" }],
IDCRD = [{ id: 3, status: "Y" }, { id: 4, status: "Y" }, { id: 2, status: "N" }, { id: 5, status: "Y" }, { id: 1, status: "N" }],
result = stud.map(o => Object.assign({}, o, IDCRD.find(({ id }) => id === o.id)));
console.log(result);
.as-console-wrapper { max-height: 100% !important; top: 0; }

Related

How to transform a dataset and aggregate values with javascript/typescript

I want to take a dataset which is an object where the the value field has an array value. I want to iterate through the array and group them by the different ids. I also want it to get an aggregate of "count"(total count) and have a field for the different type of "status" and its associated count.
"value": [
{
"count": 5,
"id": "id1",
"status": 1
},
{
"count": 2,
"id": "id1",
"status": 3
},
{
"count": 2,
"id": "id1",
"status": 4
},
{
"count": 1,
"id": "id2",
"status": 0
},
{
"count": 2,
"id": "id2",
"status": 1
},
{
"count": 7,
"id": "id2",
"status": 2
},
{
"count": 5,
"id": "id2",
"status": 3
},
{
"count": 3,
"id": "id2",
"status": 4
}
]
}```
desired output is a map where the keys are ids and value is made up of totalCount(aggregate of all the counts of that id), statusx(where x is the different type of status. There will be a limited type of status. Maybe 5 or so) that has the count of that status, and "status" to show what type of status it is(0-5):
{
id1 : { totalCount: 9, status1 : 5, status3: 2, status4:2},
id2 : { totalCount: 18, status0 : 1, status1 : 2, status2: 7, status3: 5, status4:3}
}
Super specific and weird ask, but here ya go. You can do this easily with the reduce method:
const object = {
value: [
{
count: 5,
id: 'id1',
status: 1,
},
{
count: 2,
id: 'id1',
status: 3,
},
{
count: 2,
id: 'id1',
status: 4,
},
{
count: 1,
id: 'id2',
status: 0,
},
{
count: 2,
id: 'id2',
status: 1,
},
{
count: 7,
id: 'id2',
status: 2,
},
{
count: 5,
id: 'id2',
status: 3,
},
{
count: 3,
id: 'id2',
status: 4,
},
],
};
interface Output {
[key: string]: {
totalCount: number;
[key: string]: number;
};
}
const group = ({ value }: typeof object) => {
return value.reduce((acc: Output, { count, id, status }) => {
if (!acc[id]) acc[id] = { totalCount: count };
else acc[id].totalCount += count;
if (!acc[id][`status${status}`]) acc[id][`status${status}`] = 1
else acc[id][`status${status}`] += 1
return acc;
}, {} as Output);
};
console.dir(group(object));
Compiled:
"use strict";
const object = {
value: [
{
count: 5,
id: 'id1',
status: 1,
},
{
count: 2,
id: 'id1',
status: 3,
},
{
count: 2,
id: 'id1',
status: 4,
},
{
count: 1,
id: 'id2',
status: 0,
},
{
count: 2,
id: 'id2',
status: 1,
},
{
count: 7,
id: 'id2',
status: 2,
},
{
count: 5,
id: 'id2',
status: 3,
},
{
count: 3,
id: 'id2',
status: 4,
},
],
};
const group = ({ value }) => {
return value.reduce((acc, { count, id, status }) => {
if (!acc[id])
acc[id] = { totalCount: count };
else
acc[id].totalCount += count;
if (!acc[id][`status${status}`])
acc[id][`status${status}`] = 1;
else
acc[id][`status${status}`] += 1;
return acc;
}, {});
};
console.dir(group(object));
This is written in TypeScript. You can refer to: https://www.typescriptlang.org/docs/handbook/2/indexed-access-types.html if you want to learn more about the 'index access types'
Edit: https://stackblitz.com/edit/typescript-cbfodv, working stackblitz code is available here.
const dataArray = [
{
count: 5,
id: 'id1',
status: 1,
},
{
count: 2,
id: 'id1',
status: 3,
},
{
count: 2,
id: 'id1',
status: 4,
},
{
count: 1,
id: 'id2',
status: 0,
},
{
count: 2,
id: 'id2',
status: 1,
},
{
count: 7,
id: 'id2',
status: 2,
},
{
count: 5,
id: 'id2',
status: 3,
},
{
count: 3,
id: 'id2',
status: 4,
},
];
var obj: { [k: string]: any } = {};
dataArray.forEach((elem) => {
let foundGroup = obj[elem.id];
let statusPropertyName = 'status' + elem.status;
if (foundGroup === undefined) {
obj[elem.id] = {
totalCount: elem.count,
[statusPropertyName]: elem.count,
};
} else {
foundGroup['totalCount'] += elem.count;
let foundStatus = foundGroup[statusPropertyName];
if (foundStatus === undefined) {
foundGroup[statusPropertyName] = elem.count;
} else {
foundStatus += elem.count;
}
}
});
console.log(obj);

unable to change the items based on id and expected result should be in output format

unable to change the items based on id and expected result should be in output format
const items = [
{ id: 1, value: "first" },
{ id: 2, value: "second" },
{ id: 3, value: "third" }
];
const expectedOutput = [
{ id: 1, value: "first" },
{ id: 2, value: "newvalue" },
{ id: 3, value: "third" }
]
function getData(value, id) {
return items.map((_each)=> {
if(_each.id === id) {
//need to update items with id=2
}
})
}
console.log(getData("newvalue", 2))
let inputArr = {
"data": [{
"id": 1,
"value": "first",
"row": "A"
},
{
"id": 2,
"value": "second",
"row": "A"
},
{
"id": 3,
"value": "Third",
"row": "B"
},
{
"id": 4,
"value": "Fourth",
"row": "B"
}
]
}
function format(inputArr) {
let arr = []
let obj = {};
inputArr.data.forEach(el => {
obj = {
...obj,
[el.row]: [...(obj[el.row] || []) , el.value],
}
});
arr.push(obj);
return arr;
}
let outputArr = format(inputArr)
console.log(outputArr)
let expectedOutput = [{
"A": ["first", "second"]
}, {
"B": ["Third", "Fourth"]
}]
#chidananda,
Map callback should return updated item. Minor modification to your code would work!
const items = [
{ id: 1, value: "first" },
{ id: 2, value: "second" },
{ id: 3, value: "third" }
];
const expectedOutput = [
{ id: 1, value: "first" },
{ id: 2, value: "newvalue" },
{ id: 3, value: "third" }
]
function getData(value, id) {
return items.map((_each)=> {
if(_each.id === id) {
_each.value = value;
}
return _each; // Return the modified item
})
}
console.log(getData("newvalue", 2))

Build tree from JSON array of objects

Given the following JSON Array:
[{"ID":12,"NAME":"ktc","PARENTID":0},
{"ID":11,"NAME":"root","PARENTID":0},
{"ID":1,"NAME":"rwhitney","PARENTID":0},
{"ID":21,"NAME":"shared folder","PARENTID":0},
{"ID":2,"NAME":".config","PARENTID":1},
{"ID":5,"NAME":"wallpapers","PARENTID":1},
{"ID":3,"NAME":"geany","PARENTID":2},
{"ID":4,"NAME":"colorschemes","PARENTID":3},
{"ID":13,"NAME":"efast","PARENTID":12},
{"ID":15,"NAME":"includes","PARENTID":13},
{"ID":14,"NAME":"views","PARENTID":13},
{"ID":17,"NAME":"css","PARENTID":15},
{"ID":16,"NAME":"js","PARENTID":15}]
I need to build a menu tree with the subfolders nested beneath the parent folders.
Here is some server side code:
socket.on('get-folders', function(data){
var folders = [];
getSession(session.key, function(currSession){
db.rows('getFolders', currSession, [currSession.user], function(err, rows){
if (err) {
socket.emit('err', 'Error is: ' + err );
} else if(rows[0]){
//~ folders.push(JSON.stringify(rows));
socket.emit('get-folders', JSON.stringify(rows));
//~ n_Folders(rows, currSession, socket, folders, 0);
}
});
});
});
and client side:
function rtnSocket(cmd, data, cb){
socket.emit(cmd, data);
socket.on(cmd, cb);
}
rtnSocket('get-folders', folderid, function(data){
console.log(data);
});
can someone please help guide me in the right direction?
You could collect all nodes from a flat data structure, use the ID and PARENTID as keys in a hash table and get the root array as result.
var data = [{ ID: 12, NAME: "ktc", PARENTID: 0 }, { ID: 11, NAME: "root", PARENTID: 0 }, { ID: 1, NAME: "rwhitney", PARENTID: 0 }, { ID: 21, NAME: "shared folder", PARENTID: 0 }, { ID: 13, NAME: "efast", PARENTID: 12 }, { ID: 2, NAME: ".config", PARENTID: 1 }, { ID: 5, NAME: "wallpapers", PARENTID: 1 }, { ID: 15, NAME: "includes", PARENTID: 13 }, { ID: 14, NAME: "views", PARENTID: 13 }, { ID: 3, NAME: "geany", PARENTID: 2 }, { ID: 17, NAME: "css", PARENTID: 15 }, { ID: 16, NAME: "js", PARENTID: 15 }, { ID: 4, NAME: "colorschemes", PARENTID: 3 }],
tree = function (data, root) {
var t = {};
data.forEach(o => {
Object.assign(t[o.ID] = t[o.ID] || {}, o);
t[o.PARENTID] = t[o.PARENTID] || {};
t[o.PARENTID].children = t[o.PARENTID].children || [];
t[o.PARENTID].children.push(t[o.ID]);
});
return t[root].children;
}(data, 0);
console.log(tree);
.as-console-wrapper { max-height: 100% !important; top: 0; }
Its better to put the subFolders in inside the Parent Object as SubFolder Array .. it will eliminate ParentID and make easy to traverse
[
{
"ID": 1,
"NAME": "rwhitney",
"PARENTID": 0,
"SUB": [
{
"ID": 2,
"NAME": ".config",
"PARENTID": 1,
"SUB": [
{
"ID": 3,
"NAME": "geany",
"PARENTID": 2,
"SUB": [
{
"ID": 4,
"NAME": "colorschemes",
"PARENTID": 3
}
]
}
]
},
{
"ID": 5,
"NAME": "wallpapers",
"PARENTID": 1
}
]
}
]
At first we need to flat nested array:
const flatArray = (arr) => {
return arr.reduce((flat, toFlatten) => {
return flat.concat(Array.isArray(toFlatten) ? flatArray(toFlatten) : toFlatten);
}, []);
}
Then we can create a tree:
const makeTree = dataset => {
let hashTable = Object.create(null)
dataset.forEach( aData => hashTable[aData.ID] = { ...aData, childNodes : [] } )
let dataTree = []
dataset.forEach( aData => {
if( aData.PARENTID ) hashTable[aData.PARENTID].childNodes.push(hashTable[aData.ID])
else dataTree.push(hashTable[aData.ID])
} )
return dataTree
}
An example:
let data = [
[{ ID: 12, NAME: "ktc", PARENTID: 0 }, { ID: 11, NAME: "root", PARENTID: 0 }, { ID: 1, NAME: "rwhitney", PARENTID: 0 },
{ ID: 21, NAME: "shared folder", PARENTID: 0 }], [{ ID: 13, NAME: "efast", PARENTID: 12 }], [{ ID: 2, NAME: ".config", PARENTID: 1 },
{ ID: 5, NAME: "wallpapers", PARENTID: 1 }], [{ ID: 15, NAME: "includes", PARENTID: 13 }, { ID: 14, NAME: "views", PARENTID: 13 }],
[{ ID: 3, NAME: "geany", PARENTID: 2 }], [{ ID: 17, NAME: "css", PARENTID: 15 }, { ID: 16, NAME: "js", PARENTID: 15 }],
[{ ID: 4, NAME: "colorschemes", PARENTID: 3 }]];
const flatArray = (arr) => {
return arr.reduce((flat, toFlatten) => {
return flat.concat(Array.isArray(toFlatten) ? flatArray(toFlatten) : toFlatten);
}, []);
}
const makeTree = dataset => {
let hashTable = Object.create(null)
dataset.forEach( aData => hashTable[aData.ID] = { ...aData, childNodes : [] } )
let dataTree = []
dataset.forEach( aData => {
if( aData.PARENTID ) hashTable[aData.PARENTID].childNodes.push(hashTable[aData.ID])
else dataTree.push(hashTable[aData.ID])
} )
return dataTree
}
const dataTree = makeTree(flatArray(data));
console.log(dataTree)
I need to answer my own question with the help of Nina above:
With the given JSON object - answer from Nina:
[{"ID":12,"NAME":"ktc","PARENTID":0},{"ID":11,"NAME":"root","PARENTID":0},{"ID":1,"NAME":"rwhitney","PARENTID":0},{"ID":21,"NAME":"shared folder","PARENTID":0},{"ID":2,"NAME":".config","PARENTID":1},{"ID":5,"NAME":"wallpapers","PARENTID":1},{"ID":3,"NAME":"geany","PARENTID":2},{"ID":4,"NAME":"colorschemes","PARENTID":3},{"ID":13,"NAME":"efast","PARENTID":12},{"ID":15,"NAME":"includes","PARENTID":13},{"ID":14,"NAME":"views","PARENTID":13},{"ID":17,"NAME":"css","PARENTID":15},{"ID":16,"NAME":"js","PARENTID":15},{"ID":27,"NAME":"images","PARENTID":16}]
I came up with this function:
var LHR= '',folderid = 0, parentid = 0;
var seg = location.pathname.split('/')[2];
if(seg){
LHR = seg.split('_')[0];
folderid = seg.split('_')[1] || 0;
//~ alert(folderid);
parentid = seg.split('_')[2] || 0;
if(isLike(LHR,['share']) == true){
sharedFileID = LHR.split('-')[1];
}
}
LHR = LHR.replace(/%20/g,' ');
var MLHR = isLike(LHR, ['share']) == true ? LHR.split('-')[0] : LHR;
var folders = '';
function recurse(data, indent, limit){
if(limit < 10){
for(var i = 0;i<data.length;i++){
if(folderid == data[i].ID){
folders += '<div><input style="margin-left:60px" type="checkbox" data-id="'+folderid+'" data-name="' + data[i].NAME + '" class="check-folder tooltip">'+
'<img style="margin-left:0px" data-pid="'+parentid+'" id="folder-'+folderid+'" src="/fa/folder-open.svg" class="blk tooltip"> ' + MLHR.replace(/%20/g,' ') + ' </div>';
} else {
folders += '<input type="checkbox" style="margin-left:'+indent+'px" data-id="'+data[i].ID+'" data-name="' + data[i].NAME + '" class="check-folder tooltip">'+
'<a style="margin-left:70px" ondrop="drop(event)" ondragover="allowDrop(event)" class="dsp-ib w150 blk folders drop drag" draggable="true" droppable="true" href="/dashboard/'+data[i].NAME+'_'+data[i].ID+'_'+data[i].PARENTID+'">'+
'<img data-pid="'+data[i].PARENTID+'" src="/fa/folder.svg" class="fa ml--80 blk dsp-ib" id="folder-'+data[i].ID+'"> ' + data[i].NAME + '</a><br>';
}
if(data[i].children){
recurse(data[i].children, indent+=20, ++limit);
}
}
}
$('#folders').html(folders);
}
and call it like thus:
recurse(data,0,0);
The function populates the tree of id "folders"
with the following output:
Thanks again for setting me on the right track!

Check if an element is common between 2 arrays and then assign values from it

In my angular 8 application, I have 2 arrays:
array1 = [{
"SubType": "2|3|4|5|6",
},
{
"SubType": "2",
},
{
"SubType": "3|4",
},
{
"SubType": "6",
},
{
"SubType": "3|6",
},
]
&
array2 = [{
"id": 2,
"type": "1",
},
{
"id": 3,
"type": "5",
},
{
"id": 4,
"type": "4",
},
{
"id": 5,
"type": "3",
},
{
"id": 6,
"type": "2",
}
]
I am trying to check each "SubType" in array1 and see if that element(id) is present in array2 and if present assign its "type" to a variable. "SubType" is | separated which I and converting to an array using array1..split('|'). This when assigning to a variable will need to be comma separated. I tried using array filter but I am not able to find a way to loop thorough the second array. Can anyone help?
array1.forEach(reg => {
if (reg.SubType) {
let subTypeTemp = reg.SubType.split('|');
let tempVariable = subTypeTemp.some(ele => {
let stringToassign = '';
for (let i = 0; i < array2.length; i++) {
if (ele == array2[i].id) {
stringToassign += array2[i].type + ",";
}
}
})
}
})
const array1 = [
{
SubType: "2|3|4|5|6"
},
{ SubType: "2" },
{ SubType: "3|4" },
{ SubType: "6" },
{ SubType: "3|6" }
];
const array2 = [
{
id: 2,
type: "1"
},
{ id: 3, type: "5" },
{ id: 4, type: "4" },
{ id: 5, type: "3" },
{ id: 6, type: "2" }
];
const array2Obj = array2.reduce(
(acc, curr) => ({
...acc,
[curr.id]: curr.type
}),
{}
);
const types = [];
array1.forEach(item => {
const sub_types = item.SubType.split("|");
sub_types.forEach(st => {
if (st in array2Obj) {
types.push(array2Obj[st]);
}
});
});
const types_str = [...new Set(types)].join(',');
console.log("types", types_str);
You could take a Map and prevent looping array2 over and over for getting type of a wanted id.
var array1 = [{ SubType: "2|3|4|5|6" }, { SubType: "2" }, { SubType: "3|4" }, { SubType: "6" }, { SubType: "3|6" }],
array2 = [{ id: 2, type: "1" }, { id: 3, type: "5" }, { id: 4, type: "4" }, { id: 5, type: "3" }, { id: 6, type: "2" }],
types = new Map(array2.map(({ id, type }) => [id.toString(), type])),
result = array1.map(({ SubType }) => SubType
.split('|')
.map(Map.prototype.get, types)
.join()
);
console.log(result);

Dynamically add objects to an array

I want to create a datasource dynamically for my table from a array of objects.
Required datasource value:
values = [
{
name: "Super Admin"
cv: 1
assessment1_title: score/status
assessment2_title: score/status
interview1_title: score/status
interview2_title: score/status
}
]
I have the following array of object:
data = {
"assessments": [
{
"id": 6,
"title": "PHP Laravel Developer",
"type": "Objective"
},
{
"id": 7,
"title": "Laravel Developer",
"type": "Objective"
}
],
"candidates": [
{
"id": 11,
"user_id": 1,
"user_name": "Super Admin",
"assessments": [
{
"id": 1,
"score": 5,
"duration": 1170,
"status": {
"id": 22,
"name": "completed"
}
},
{
"id": 2,
"score": 0,
"duration": 0,
"status": {
"id": 22,
"name": "Pending"
}
}
]
}
]
}
where the value of assessment_title will be dynamically generated from data.assessments.map(({title}) => title) and the value will be one of score and status
data.canditates.map(res => res.assessments.map(res2=> {
if res2.status.id ==22 {
value = res2.score
} else {
value = res2.status.name
}
})
);
I want to make the required datasource value. Thanks in advance
You can get the desired result by using reduce on candidates and then forEach assessments element add title and score/status.
const data = {"assessments":[{"id":6,"title":"PHP Laravel Developer","type":"Objective"},{"id":7,"title":"Laravel Developer","type":"Objective"}],"candidates":[{"id":11,"user_id":1,"user_name":"Super Admin","assessments":[{"id":1,"score":5,"duration":1170,"status":{"id":22,"name":"completed"}},{"id":2,"score":0,"duration":0,"status":{"id":22,"name":"Pending"}}]}]}
const result = data.candidates.reduce((r, c) => {
const obj = {}
obj.cv = c.user_id;
obj.name = c.user_name;
c.assessments.forEach((e, i) => {
const {score, status: {name}} = e;
const {title} = data.assessments[i];
obj[title] = e.status.id === 22 ? name : score;
})
r.push(obj)
return r;
}, [])
console.log(result)
You could also create a bit more flexible solution that will work in case you have more then two keys in original object.
const data = {"assessments":[{"id":6,"title":"PHP Laravel Developer","type":"Objective"},{"id":7,"title":"Laravel Developer","type":"Objective"}],"interviews":[{"id":1,"title":"Interview 1"},{"id":2,"title":"Interview 2"}],"candidates":[{"id":11,"user_id":1,"user_name":"Super Admin","interviews":[{"id":1,"score":3,"status":{"name":"completed"}},{"id":2,"score":0,"status":{"name":"pending"}}],"assessments":[{"id":1,"score":5,"duration":1170,"status":{"id":22,"name":"completed"}},{"id":2,"score":0,"duration":0,"status":{"id":22,"name":"Pending"}}]}]}
const result = data.candidates.reduce((r, c) => {
const obj = {}
obj.cv = c.user_id;
obj.name = c.user_name;
Object.keys(data).forEach(k => {
if(k !== 'candidates') {
data[k].forEach((e, i) => {
const {title} = e;
const {score, status: {name}} = c[k][i];
obj[title] = `${score}/${name}`
})
}
})
r.push(obj)
return r;
}, [])
console.log(result)
My solution would be something like below.
data = {
assessments: [
{
id: 6,
title: "PHP Laravel Developer",
type: "Objective"
},
{
id: 7,
title: "Laravel Developer",
type: "Objective"
}
],
candidates: [
{
id: 11,
user_id: 1,
user_name: "Super Admin",
assessments: [
{
id: 6,
score: 5,
duration: 1170,
status: {
id: 22,
name: "completed"
}
},
{
id: 7,
score: 0,
duration: 0,
status: {
id: 21,
name: "Pending"
}
}
]
}
]
};
assessments_map = data.assessments.reduce((acc, val) => {
const {id,...rest} = val;
acc[id] = rest;
return acc
}, {});
assessments_map;
a = data.candidates.map((candidate) => {
return {name: candidate.user_name,
...candidate.assessments.reduce((acc, assessment) => {
acc[assessments_map[assessment.id].title] =
assessment.status.id == 22
? assessment.score
: assessment.status.name;
return acc;
}, {})
}
});
console.log(a);

Categories