1
2//For Values
3var arr =[1,10,3]
4var min = Math.min.apply(null, arr),
5 max = Math.max.apply(null, arr);
6
7//For Objects
8var arr = [{a: 1},{a: 10},{a: 3}]
9var values = arr.map(val => val.a);
10var max = Math.max.apply(null, values);
11console.log(max)
12
1var peopleData = [
2 { name: "Paul", height: 180, age: 21 },
3 { name: "Johnny", height: 198, age: 43 },
4 { name: "Brad", height: 172, age: 49 },
5 { name: "Dwayne", height: 166, age: 15 }
6];
7
8//Find biggest height number
9var maxHeight = 0;
10
11for (var i = 0; i < heights.length; i++) {
12 if (peopleData[i].height > maxHeight) {
13 maxHeight = peopleData[i].height;
14 //if you console.log(maxHeight); you should get 198
15 }
16}
1function maisBaratosQue(valor, precos) {
2 return precos.filter(p => p <= valor);
3}
1//For Values
2var arr =[1,10,3]
3var min = Math.min.apply(null, arr),
4 max = Math.max.apply(null, arr);
5
6//For Objects
7var arr = [{a: 1},{a: 10},{a: 3}]
8var values = arr.map(val => val.a);
9var max = Math.max.apply(null, values);
10console.log(max)
1
2function nthlargest(arra,highest){
3 var x = 0,
4 y = 0,
5 z = 0,
6 temp = 0,
7 tnum = arra.length,
8 flag = false,
9 result = false;
10
11 while(x < tnum){
12 y = x + 1;
13
14 if(y < tnum){
15 for(z = y; z < tnum; z++){
16
17 if(arra[x] < arra[z]){
18 temp = arra[z];
19 arra[z] = arra[x];
20 arra[x] = temp;
21 flag = true;
22 }else{
23 continue;
24 }
25 }
26 }
27
28 if(flag){
29 flag = false;
30 }else{
31 x++;
32 if(x === highest){
33
34 result = true;
35 }
36 }
37 if(result){
38 break;
39 }
40 }
41
42 return (arra[(highest - 1)]);
43 }
44
45console.log(nthlargest([ 43, 56, 23, 89, 88, 90, 99, 652], 4));
46
47
1//get min/max value of arrays
2function getArrayMax(array){
3 return Math.max.apply(null, array);