-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArray.js
More file actions
39 lines (32 loc) · 987 Bytes
/
Copy pathArray.js
File metadata and controls
39 lines (32 loc) · 987 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
function double(arr) {
return arr.map(num => num * 2);
}
console.log(double([1, 2, 3])); // Output: [2, 4, 6]
function filterEven(arr) {
return arr.filter(num => num % 2 !== 0);
}
console.log(filterEven([1, 2, 3, 4, 5])); // Output: [1, 3, 5]
function sum(arr) {
return arr.reduce((acc, num) => acc + num, 0);
}
console.log(sum([1, 2, 3, 4])); // Output: 10
function average(arr) {
return arr.length ? sum(arr) / arr.length : 0;
}
console.log(average([1, 2, 3, 4])); // Output: 2.5
function findMax(arr) {
return Math.max(...arr);
}
console.log(findMax([1, 2, 3, 4, 5])); // Output: 5
function findMin(arr) {
return Math.min(...arr);
}
console.log(findMin([1, 2, 3, 4, 5])); // Output: 1
function removeDuplicates(arr) {
return [...new Set(arr)];
}
console.log(removeDuplicates([1, 2, 2, 3, 4, 4, 5])); // Output: [1, 2, 3, 4, 5]
function findIndex(arr, value) {
return arr.indexOf(value);
}
console.log(findIndex([1, 2, 3, 4, 5], 3)); // Output: 2