Created
October 5, 2023 04:35
-
-
Save kotoyama/2a2dc78368ca6b46d0c01674adb85b93 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const crownRanges = [ | |
{ hat: "1st hat", min: 0, max: 1499 }, | |
{ hat: "2nd hat", min: 1500, max: 2999 }, | |
{ hat: "3rd hat", min: 3000, max: 4499 }, | |
{ hat: "4th hat", min: 4500, max: Infinity } | |
]; | |
const players = [ | |
{ name: "Beefy", crowns: 1800 }, | |
{ name: "violetti_lohis", crowns: 1200 }, | |
{ name: "Auron956", crowns: 3650 }, | |
{ name: "Archsine", crowns: 1446 }, | |
{ name: "unknown", crowns: 3234 }, | |
{ name: "air_bobby", crowns: 4500 }, | |
{ name: "Bishop", crowns: 5000 }, | |
{ name: "Riemer", crowns: 2739 }, | |
{ name: "akumasimba", crowns: 3600 }, | |
{ name: "LAOS", crowns: 5600 }, | |
{ name: "janarca", crowns: 6000 }, | |
{ name: "loki4910lofiti", crowns: 2300 }, | |
{ name: "galaxystar4041", crowns: 1250 }, | |
{ name: "HUNT3R", crowns: 3000 }, | |
{ name: "golden_socks", crowns: 550 }, | |
{ name: "katdog88", crowns: 3200 }, | |
{ name: "laurax534", crowns: 4500 }, | |
{ name: "squirrelburrito", crowns: 2100 }, | |
{ name: "Altf23", crowns: 1900 }, | |
{ name: "shinykip82", crowns: 663 }, | |
{ name: "Its-ryma", crowns: 3370 }, | |
{ name: "Emz", crowns: 503 }, | |
{ name: "achieverrr", crowns: 2889 }, | |
{ name: "FullNappy", crowns: 6000 } | |
]; | |
function initializeHatGroups(crownRanges) { | |
const hatGroups = {}; | |
crownRanges.forEach((range) => { | |
hatGroups[range.hat] = []; | |
}); | |
return hatGroups; | |
} | |
const hatGroups = initializeHatGroups(crownRanges); | |
function groupPeopleByHats(people) { | |
return people.reduce((groups, person) => { | |
const hat = crownRanges.find((range) => { | |
return person.crowns >= range.min && person.crowns <= range.max; | |
}); | |
if (hat) { | |
groups[hat.hat].push(person); | |
} | |
return groups; | |
}, hatGroups); | |
} | |
const groupedPeople = groupPeopleByHats(players); | |
console.log(groupedPeople); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment