Currently, I am working on developing a unique quiz format where there are no correct or incorrect answers; instead, responses are given a score ranging from 1 to 4.
Each question falls under one of four distinct categories (such as cat, dog, rabbit, alpaca). The user's response for each question is recorded in an array with the corresponding category like so:
answersChosen = [
{key: 'cat', value: 4},
{key: 'dog', value: 2},
{key: 'rabbit', value: 1},
{key: 'alpaca', value: 3},
{key: 'cat', value: 1},
{key: 'dog', value: 4},
{key: 'rabbit', value: 1},
{key: 'alpaca', value: 2},
{key: 'cat', value: 2},
{key: 'dog', value: 1},
{key: 'rabbit', value: 4},
{key: 'alpaca', value: 3},
{key: 'cat', value: 3},
{key: 'dog', value: 4},
{key: 'rabbit', value: 1},
{key: 'alpaca', value: 2},
];
I am currently exploring ways to condense the array into the four categories with an aggregated score representing each category to identify the most common animal. In this scenario, it would be a dog:
//Updated array
results = [
{key: 'cat', value: 10},
{key: 'dog', value: 11}, //top score
{key: 'rabbit', value: 7},
{key: 'alpaca', value: 10},
];