Created
February 27, 2012 14:54
-
-
Save julio-saito-linx/1924380 to your computer and use it in GitHub Desktop.
ordenação de 3 itens com IF
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
var ordenarComIf = function(a, b, c) { | |
var primeiro = ''; | |
var segundo = ''; | |
var terceiro = ''; | |
if (a > b && a > c) { | |
primeiro = 'a'; | |
if (b > c) { | |
segundo = 'b'; | |
terceiro = 'c'; | |
} else { | |
segundo = 'c'; | |
terceiro = 'b'; | |
} | |
} | |
else if (b > a && b > c) { | |
primeiro = 'b'; | |
if (a > c) { | |
segundo = 'a'; | |
terceiro = 'c'; | |
} else { | |
segundo = 'c'; | |
terceiro = 'a'; | |
} | |
} | |
else if (c > a && c > b) { | |
primeiro = 'c'; | |
if (a > b) { | |
segundo = 'a'; | |
terceiro = 'b'; | |
} else { | |
segundo = 'b'; | |
terceiro = 'a'; | |
} | |
} | |
alert('dados os numeros: ' + a + ', ' + b + ', ' + c + ', ' + '\n' + | |
'primeiro: ' + primeiro + '\n' + | |
'segundo: ' + segundo + '\n' + | |
'terceiro: ' + terceiro); | |
}; | |
ordenarComIf(2, 4, 3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment