forked from inpg-batch-13/number-processing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
46 lines (36 loc) · 905 Bytes
/
script.js
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
46
function min(arr) {
return Math.min (...arr)
}
function max(arr) {
return arr.reduce(function(x,y){
return (x > y) ? x : y
})
}
function mean(arr) {
var total = 0
for (var i = 0; i < arr.length; i++) {
total += arr[i]
}
return total /= arr.length
}
function odds(arr) {
var result = []
for (var i = 0; i < arr.length; i++) {
if (arr[i] % 2 !== 0) {
result.push(arr[i])
}}
return result.join('-')
}
function evens(arr) {
var result = []
for (var i = 0; i < arr.length; i++) {
if (arr[i] % 2 === 0) {
result.push(arr[i])
}}
return result.join ('-')
}
function numberProcessing(arr) {
return 'Min: ' + min(arr) + ', Max: ' + max(arr) + ', Mean: ' + mean(arr) + ', Odds: ' + odds(arr) + ', Evens: ' + evens(arr)
}
console.log(numberProcessing([1, 3, 5, 1, 2, 8, 10, 0, 3]))
// "Min: 0, Max: 10, Mean: 4, Odds: 1-3-5-1-3, Evens: 2-8-10-0