Skip to content

Instantly share code, notes, and snippets.

@diegopso
Last active August 29, 2015 14:03
Show Gist options
  • Save diegopso/ec74931672f696a73e78 to your computer and use it in GitHub Desktop.
Save diegopso/ec74931672f696a73e78 to your computer and use it in GitHub Desktop.
Amigo Secreto
amigoSecreto = function (vet) {
r = [];
for(i = 0; i < vet.length - 1; i++) {
r.push([vet[i], vet[i + 1]]);
}
r.push([vet[i], vet[0]]);
return r;
};
amigoSecreto2 = function (vet) {
r = [];
l = vet.length;
a = Math.floor((Math.random() * l));
b = Math.floor((Math.random() * l));
temp = vet[a];
vet[a] = vet[b];
vet[b] = temp;
for(i = 0; i < l - 1; i++) {
r.push([vet[i], vet[i + 1]]);
}
r.push([vet[i], vet[0]]);
return r;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment