-
Notifications
You must be signed in to change notification settings - Fork 0
/
kata.js
33 lines (22 loc) · 823 Bytes
/
kata.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
// #1
// function sumArray(array) {
// return array === null || array === undefined || array.length <=1 ? 0 : array.sort((a,b)=>a-b).reduce((acc, i, idx) => idx===0 || idx===array.length-1 ? acc : acc+i, 0);
// }
// #2
const sumArray = arr => Array.isArray(arr) && arr.length >= 3 ? arr.reduce((acc, i) => acc + i, 0) - Math.max(...arr) - Math.min(...arr) : 0;
console.log(sumArray(null));
// , 0
console.log(sumArray([]));
// , 0
console.log(sumArray([3]));
// , 0
console.log(sumArray([3, 5]));
// , 0
console.log(sumArray([6, 2, 1, 8, 10]));
// , 16
console.log(sumArray([0, 1, 6, 10, 10]));
// , 17
console.log(sumArray([-6, -20, -1, -10, -12]));
//, -28
console.log(sumArray([-6, 20, -1, 10, -12]));
// , 3