Last active
August 29, 2015 14:03
-
-
Save diegopso/ec74931672f696a73e78 to your computer and use it in GitHub Desktop.
Amigo Secreto
This file contains hidden or 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
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; | |
}; |
This file contains hidden or 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
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