I have a JSON that looks like this:
{
"user": [
{"username": "x1", "pfp": "", "scores": [{"easy": 10, "normal": 1, "hard": 2, "oni": 3, "uraoni": 4}]},
{"username": "x2", "pfp": "", "scores": [{"easy": 3, "normal": 1, "hard": 2, "oni": 3, "uraoni": 4}]},
{"username": "x3", "pfp": "", "scores": [{"easy": 5, "normal": 1, "hard": 2, "oni": 3, "uraoni": 4}]},
{"username": "x4", "pfp": "", "scores": [{"easy": 0, "normal": 40, "hard": 2, "oni": 3, "uraoni": 4}]}
]
}
Expected output of the order by username: x4, x1, x3, x2 (x4 would have a value of 49, x1 a value of 20, x2 a value of 15 and x3 a value of 13).
and I need to map() the array in the order of the sum of the scores array.
I tried doing a map for reduce() the scores and then sort() it but it didn't let me reduce() it.
let userscopy = userjson
userscopy.map((user) => (
user.scores[0] = JSON.parse(user.scores).reduce((a, b) => a + b)
))
