I have an array of correct ratings that looks like this:
var correctScores = [
{score: "2-2", code: "draw"},
{score: "2-1", code: "home"},
{score: "0-1", code: "away"},
{score: "1-0", code: "home"},
{score: "3-0", code: "home"},
{score: "any home win", code: "home"},
{score: "1-2", code: "away"},
{score: "0-3", code: "away"},
{score: "any draw", code: "draw"},
{score: "0-0", code: "draw"},
{score: "any away win", code: "away"},
{score: "0-2", code: "away"},
{score: "1-1", code: "draw"},
{score: "2-0", code: "home"}
]
I was able to sort them by home, draw, awaybut I'm also trying to spread it to the account to be in sequential order. When I talk about sequential order, I want the ratings to be ordered so that the least number of goals is the first in the array. After that, if there are the same number of goals, the game with more home goals should be shown first.
home, draw, away. , . , , .
let order = { HOME: 1, DRAW: 2, AWAY: 3 };
correctScores.sort(function (a, b) { return order[a.code] - order[b.code]; });
:
var correctScores = [
{score: "1-0", code: "home"},
{score: "2-0", code: "home"},
{score: "3-0", code: "home"},
{score: "2-1", code: "home"},
{score: "any home win", code: "home"}
{score: "0-0", code: "draw"},
{score: "1-1", code: "draw"},
{score: "2-2", code: "draw"},
{score: "any draw", code: "draw"},
{score: "0-1", code: "away"},
{score: "0-2", code: "away"},
{score: "0-3", code: "away"},
{score: "1-2", code: "away"},
{score: "any away win", code: "away"}
]
- - , ?