How to sort and get max value from 3 array of objects and assign the keys and values to another array?
I want to sort the arrays test1, test2, test3 and get the max score for a student and assign it to the array results as an object like
results = [{name: name, score: score}]
I am able to get the highest score out of all the tests but finding it a bit difficult to get the names and assigning it as an object to the results array
const test1 = [{name: 'vikash', score: 1}, {name: 'krish', score: 2}, {name: 'kunz', score: 3}]
const test2 = [{name: 'kunz', score: 4}, {name: 'vikash', score: 5}, {name: 'krish', score: 6}]
const test3 = [{name: 'krish', score: 7}, {name: 'kunz', score: 8}, {name: 'vikash', score: 9}]
const results = []
const maxScore = Math.max(Math.max(...test1.map(test => test.score)), Math.max(...test2.map(test => test.score)), Math.max(...test3.map(test => test.score)));
// prints highest score out of the 3 tests: 9
console.log(maxScore )
The results array should look like this at the end of it ..
resutls = [{name: 'vikash', score: 9}]