Assignment 1

an anonymous user · April 08, 2021 · NodeJS
let students = [
    [
        ["roll",101],
        ["name","John"],
        ["course","BTech"]
    ],
    [
        ["roll",102],
        ["name","Anna"],
        ["course","MTech"]
    ],
    [
        ["roll",103],
        ["name","Rajat"],
        ["course","BSc"]
    ],
    [
        ["roll",104],
        ["name","Mayank"],
        ["course","BCA"]
    ],
    [
        ["roll",105],
        ["name","Ritesh"],
        ["course","MCA"]
    ]
];

let results = [
    [
        ["roll",101],
        ["Marks",82],
        ["Grade","B"]
    ],
    [
        ["roll",102],
        ["Marks",92],
        ["Grade","A"]
    ],
    [
        ["roll",103],
        ["Marks",72],
        ["Grade","C"]
    ],
    [
        ["roll",104],
        ["Marks",62],
        ["Grade","D"]
    ],
    [
        ["roll",105],
        ["Marks",52],
        ["Grade","E"]
    ]
];

let studentsObj = students.map(student => Object.fromEntries(student));
console.log(studentsObj);

let resultsObj = results.map(result => Object.fromEntries(result));
console.log(resultsObj);

let students_results = [];

for (let i = 0; i < studentsObj.length; i++) {
    let student = studentsObj[i];
    let result = resultsObj[i];
    students_results[i] = {...student, ...result};
}

console.log(students_results);

Comments

Please sign up or log in to contribute to the discussion.