Minor changes to make code neater
This commit is contained in:
parent
819ca3fa16
commit
9529bafac6
1 changed files with 7 additions and 5 deletions
12
main.js
12
main.js
|
@ -6,23 +6,25 @@ request.open(
|
||||||
request.send();
|
request.send();
|
||||||
|
|
||||||
request.onload = function() {
|
request.onload = function() {
|
||||||
|
let ending = x => (Math.abs(x) === 1 ? "" : "s")
|
||||||
|
|
||||||
let teams = JSON.parse(this.response)
|
let teams = JSON.parse(this.response)
|
||||||
let totals = teams.map(team => team.lineup.length + team.rotation.length)
|
let totals = teams.map(team => team.lineup.length + team.rotation.length)
|
||||||
// Get all player counts that there are from greatest to least
|
// Get all player counts that there are from greatest to least
|
||||||
// & make headers & lists for them
|
// & make headers & lists for them
|
||||||
totals.slice().sort((x, y) => y - x)
|
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) {
|
.forEach(function(item) {
|
||||||
document.body.insertAdjacentHTML("beforeend",
|
document.body.insertAdjacentHTML("beforeend",
|
||||||
`<h1>${item} player${(item > 1 ? "s" : "")}</h1>
|
`<h1>${item} player${ending(item)}</h1>
|
||||||
<ul id="tlist${item}"></ul>`)
|
<ul id="tlist${item}"></ul>`)
|
||||||
})
|
})
|
||||||
// Put the teams in the lists
|
// Put the teams in the lists
|
||||||
teams.forEach(function(item, pos) {
|
teams.forEach(function(item, pos) {
|
||||||
document.getElementById("tlist" + totals[pos]).insertAdjacentHTML("beforeend",
|
document.getElementById("tlist" + totals[pos]).insertAdjacentHTML("beforeend",
|
||||||
`<li>${item.fullName}
|
`<li>${item.fullName}
|
||||||
(${item.lineup.length} hitter${(item.lineup.length > 1 ? "s" : "")},
|
(${item.lineup.length} hitter${ending(item.lineup.length)},
|
||||||
${item.rotation.length} pitcher${(item.rotation.length > 1 ? "s" : "")})</li>`)
|
${item.rotation.length} pitcher${ending(item.rotation.length)})</li>`)
|
||||||
})
|
})
|
||||||
|
|
||||||
document.getElementById("progress").remove()
|
document.getElementById("progress").remove()
|
||||||
|
|
Loading…
Reference in a new issue