Created
April 28, 2021 14:02
-
-
Save isaacbatst/d84ca72c94d2f154ca27690ab3bd338a 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
// Primeiro Sistema | |
// 1: 10, 2: 8, 3: 6, 4: 5, 5: 4, 6:3, 7: 2, 8: 1 | |
let firstSystem = [10, 8, 6, 5, 4, 3, 2, 1]; | |
// Segundo Sistema | |
// 1: 25, 2: 18, 3: 15, 4: 12, 5: 10, 6: 8, 7: 6, 8: 4, 9: 2, 10: 1 | |
let secondSystem = [25, 18, 15, 12, 10, 8, 6, 4, 2 , 1]; | |
// Resultado da Corrida | |
// 1: Rubinho, 2: Schumacher, 3: Alonso, 4: Hamilton | |
let pilotsPositions = ['rubinho', 'schumacher', 'alonso', 'hamilton', 'aaaa', 'bbbb', 'ccccc', 'dddd', 'eeee', 'massa']; | |
//Calcular pontuação pro primeiro sistema | |
//Juntar nome do piloto, com resultado da posição | |
function calcScore(system){ | |
let score = {}; | |
for(let index = 0; index < pilotsPositions.length; index += 1){ | |
let pilot = pilotsPositions[index]; | |
if((system.length - 1) < index) { | |
score[pilot] = 0 | |
} else { | |
score[pilot] = system[index] | |
} | |
} | |
return score; | |
} | |
console.log(calcScore(firstSystem)) | |
console.log(calcScore(secondSystem)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment