|
| 1 | +const points = ["Banana", "Orange", "Coconut", "Mango"]; |
| 2 | + |
| 3 | +//sort an array in descending order |
| 4 | +points.sort(); |
| 5 | + |
| 6 | +//reverse the array |
| 7 | +points.reverse(); |
| 8 | + |
| 9 | + |
| 10 | +const num1 = [11, 2, 32, 5, 12]; |
| 11 | + |
| 12 | +//Creates a new array by performing a function on each array element |
| 13 | +const num2 = numbers1.map(myFunction); |
| 14 | +function myFunction(value, index, array) { |
| 15 | + return value * 4; |
| 16 | +} |
| 17 | + |
| 18 | +//Creates a new array with all array elements that passes a test |
| 19 | +const num3 = num1.filter(myFunction); |
| 20 | +function myFunction(value, index, array) { |
| 21 | + return value > 19; |
| 22 | +} |
| 23 | + |
| 24 | +//The every() method checks if all array values pass a test |
| 25 | +let all1 = num1.every(myFunction); |
| 26 | + |
| 27 | +function myFunction(value) { |
| 28 | + return value > 11; |
| 29 | +} |
| 30 | + |
| 31 | +//The some() method checks if some array values pass a test |
| 32 | +let all2 = numbers.some(myFunction); |
| 33 | + |
| 34 | +function myFunction(value, index, array) { |
| 35 | + return value > 13; |
| 36 | +} |
0 commit comments