From 9529bafac6de56db4ac38ff3068377f21946a696 Mon Sep 17 00:00:00 2001 From: endie Date: Thu, 1 Apr 2021 01:21:15 +0000 Subject: [PATCH] Minor changes to make code neater --- main.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/main.js b/main.js index cf298c1..d7845c5 100644 --- a/main.js +++ b/main.js @@ -6,23 +6,25 @@ request.open( request.send(); request.onload = function() { + let ending = x => (Math.abs(x) === 1 ? "" : "s") + let teams = JSON.parse(this.response) let totals = teams.map(team => team.lineup.length + team.rotation.length) // Get all player counts that there are from greatest to least // & make headers & lists for them totals.slice().sort((x, y) => y - x) - .filter((item, pos, array) => !pos || item != array[pos - 1]) + .filter((item, pos, array) => !pos || item !== array[pos - 1]) .forEach(function(item) { document.body.insertAdjacentHTML("beforeend", - `

${item} player${(item > 1 ? "s" : "")}

- `) + `

${item} player${ending(item)}

+ `) }) // Put the teams in the lists teams.forEach(function(item, pos) { document.getElementById("tlist" + totals[pos]).insertAdjacentHTML("beforeend", `
  • ${item.fullName} - (${item.lineup.length} hitter${(item.lineup.length > 1 ? "s" : "")}, - ${item.rotation.length} pitcher${(item.rotation.length > 1 ? "s" : "")})
  • `) + (${item.lineup.length} hitter${ending(item.lineup.length)}, + ${item.rotation.length} pitcher${ending(item.rotation.length)})`) }) document.getElementById("progress").remove()