Skip to content

Instantly share code, notes, and snippets.

@tosipaulo
Created August 31, 2018 14:21
Show Gist options
  • Save tosipaulo/1be92b04896886a61b8ea17e6726c463 to your computer and use it in GitHub Desktop.
Save tosipaulo/1be92b04896886a61b8ea17e6726c463 to your computer and use it in GitHub Desktop.
group times
const times = [{id:'time a'},{id:'time b'},{id:' time c'},{id:'time d'},{id:'time e'}];
const groups = (arr) => {
const output = [];
for(i = 0; i < arr.length; i++){
for(j = 1; j < arr.length; j++){
if(arr[i].id == arr[j].id){
continue;
}
output.push([arr[i], arr[j]])
}
}
return output
}
@tosipaulo
Copy link
Author

Essa essa logica, mas agora você falando percebi que na interação o valor time b x time a , time c x time a não estão aparecendo! Podemos melhorar ainda mais isso!

@neilsonlima
Copy link

neilsonlima commented Sep 4, 2018

Excelente solução, porém para atender minha necessidade tiver que inverter os pares com se fosse jogos da segunda fase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment