Here’s a pretty simple function that sets up data that I use later on.
const tributeDataArray = [];
for (let i = 0; i < tributes.length; i++) {
const { user } = tributes[i];
const tributeObj = {
name: user.username,
id: user.id,
avatar: user.displayAvatarURL({ format: 'png' }),
alive: true,
kills: [],
killedBy: '',
district: tributes.length === 2 ? i + 1 : Math.ceil((i + 1) / 2)
};
tributeDataArray.push(tributeObj);
}
return tributeDataArray;
}
My main annoyance is tributes.length === 2 ? i + 1 : Math.ceil((i + 1) / 2)
, Is there a cleaner way to achieve this?