1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
var numTeams = function (rating) { var count = 0; for (let i = 1; i < rating.length - 1; i++) { let ri = rating[i]; let countx1 = 0, countx2 = 0; let county1 = 0, county2 = 0; for (let x = 0; x < i; x++) { if (rating[x] < ri) countx1++; if (rating[x] > ri) countx2++; } for (let x = i + 1; x < rating.length; x++) { if (rating[x] < ri) county1++; if (rating[x] > ri) county2++; } count += countx1 * county2 + countx2 * county1; } return count; };
|