Given are these exemplary arrays:
var questions = [
{
question: 'Which of these U.S. Presidents appeared on the television series "Laugh-In"?',
hint1: '...',
hint2: '...',
hint3: '...'
},
{
question: 'The Earth is approximately how many miles away from the Sun?',
hint1: '...',
hint2: '...',
hint3: '...'
},
{
question: 'Which insect shorted out an early supercomputer and inspired the term "computer bug"?',
hint1: '...',
hint2: '...',
hint3: '...'
}
];
var answersToFirstQuestion = [
{
answer: 'Lyndon Johnson',
comment: '...'
},
{
answer: 'Richard Nixon',
comment: '...'
},
{
answer: 'Jimmy Carter',
comment: '...'
},
{
answer: 'Gerald Ford',
comment: '...'
}
];
var anwersToSecondQuestion = [
{
answerA: '9.3 million',
comment: '...'
},
{
answerB: '39 million',
comment: '...'
},
{
answerC: '93 million',
comment: '...'
},
{
answerD: '193 million',
comment: '...'
}
];
var answersToThirdQuestion = [
{
answerA: 'Moth',
comment: '...'
},
{
answerB: 'Roach',
comment: '...'
},
{
answerC: 'Fly',
comment: '...'
},
{
answerD: 'Japanese beetle',
comment: '...'
}
];
Notwithstanding the fact that it may not make sense to store the answers this way, it is just an example, how can the answer-arrays be sorted according to an order given in the form of a string?
So something like console.log(anwersToSecondQuestion.sort('A, C, B, D'));
should result in:
[
{
"answer": "Lyndon Johnson",
"comment": "..."
},
{
"answer": "Jimmy Carter",
"comment": "..."
},
{
"answer": "Richard Nixon",
"comment": "..."
},
{
"answer": "Gerald Ford",
"comment": "..."
}
]