Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function arenaTier(commands) {
- let gladiatorsPool = {}
- commands.splice(commands.indexOf("Ave Cesar"), commands.length)
- function tehniqueBattle(a, b) {
- const firstData = Object.entries(gladiatorsPool[a])
- const secondData = Object.entries(gladiatorsPool[b])
- return firstData.some(x => secondData.some(y => y.includes(x[0])))
- }
- function sum(glad) {
- return glad.reduce((a, v) => a + v[1], 0)
- }
- function sortedGladiator (a,b){
- return a.localeCompare(b)
- }
- function sumSkill(glad) {
- return glad.reduce((a, v) => a + v[1], 0)
- }
- function sortSkill(x, y) {
- return sumSkill(Object.entries(y)) - sumSkill(Object.entries(x))
- }
- for (let i = 0; i < commands.length; i++) {
- let [name, techique, skill] = commands[i].split(" -> ");
- if (techique !== undefined) {
- if (!gladiatorsPool[name]) gladiatorsPool[name] = {}
- if (!gladiatorsPool[name][techique]) gladiatorsPool[name][techique] = 0
- if (gladiatorsPool[name][techique] < Number(skill))
- gladiatorsPool[name][techique] = Number(skill)
- }else {
- let [gladiatorA, gladiatorB] = commands[i].split(" vs ")
- if(gladiatorsPool.hasOwnProperty(gladiatorA) && gladiatorsPool.hasOwnProperty(gladiatorB) ){
- if (tehniqueBattle(gladiatorA, gladiatorB)) {
- sum(Object.entries(gladiatorsPool[gladiatorA])) > sum(Object.entries(gladiatorsPool[gladiatorB]))
- ? delete gladiatorsPool[gladiatorB]
- : delete gladiatorsPool[gladiatorA]
- }
- }
- }
- }
- let sortedGlad = Object.entries(gladiatorsPool).sort((x, y) =>
- sortSkill(x[1], y[1]) !== 0 ? sortSkill(x[1], y[1]) : sortByName(x[0], y[0])
- )
- sortedGlad.forEach(x => {
- const skills = Object.entries(x[1]).sort((x, y) => (y[1] - x[1] !== 0 ? y[1] - x[1] : sortedGladiator(x[0], y[0])))
- console.log(`${x[0]}: ${sumSkill(skills)} skill`)
- skills.forEach(x => console.log(`- ${x[0]} <!> ${x[1]}`))
- })
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement