-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray_ordenacao.html
More file actions
45 lines (34 loc) · 847 Bytes
/
array_ordenacao.html
File metadata and controls
45 lines (34 loc) · 847 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Ordenação de elementos no Array</title>
<script>
/*
//.sort()-> ordenação alfabética
var lista_frutas = Array()
lista_frutas[0] = 'Maçã'
lista_frutas[1] = 'Uva'
lista_frutas[2] = 'Banana'
lista_frutas[3] = 'Morango'
console.log(lista_frutas.sort())
*/
var lista_numeros = Array()
lista_numeros[0] = '12'
lista_numeros[1] = '40'
lista_numeros[2] = '3'
lista_numeros[3] = '7'
lista_numeros[4] = '19'
lista_numeros[5] = '1'
console.log(lista_numeros.sort(ordenaNumeros))
function ordenaNumeros (a, b) {
return a-b
// <0 = a ordenado antes de b
// >0 = b ordenado antes de a
// == a ordem é mantida
}
</script>
</head>
<body>
</body>
</html>