Repository navigation
Expand file tree
/
Copy pathArrayGridSum.js
More file actions
72 lines (68 loc) · 2.18 KB
/
Copy pathArrayGridSum.js
File metadata and controls
72 lines (68 loc) · 2.18 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const sumArray = (total, num) => {
/*This will be used with the reduce method and sum up the numbers */
return total + num;
};
const sumTheArrayGrid = (one, two, three, four, five, six, seven, eight, nine) => {
/* This function will use sumArray on each of the paramaters. Paramaters should be array objects
Performs checks if each paramater is an array.
*/
let valid = false;
Array.isArray(one)
? (valid = true)
: console.error(
"TypeError : Unexpected Type one section must be an array line 145"
);
Array.isArray(two)
? (valid = true)
: console.error(
"TypeError : Unexpected Type two must be an array line 146"
);
Array.isArray(three)
? (valid = true)
: console.error(
"TypeError : Unexpected Type three must be an array line 147"
);
Array.isArray(four)
? (valid = true)
: console.error(
"TypeError : Unexpected Type four must be an array line 148"
);
Array.isArray(five)
? (valid = true)
: console.error(
"TypeError : Unexpected Type five must be an array line 149"
);
Array.isArray(six)
? (valid = true)
: console.error(
"TypeError : Unexpected Type six must be an array line 150"
);
Array.isArray(seven)
? (valid = true)
: console.error(
"TypeError : Unexpected Type seven must be an array line 151"
);
Array.isArray(eight)
? (valid = true)
: console.error(
"TypeError : Unexpected Type eight must be an array line 152"
);
Array.isArray(nine)
? (valid = true)
: console.error(
"TypeError : Unexpected Type nine must be an array line 153"
);
let gridSum = (
one.reduce(sumArray) +
two.reduce(sumArray) +
three.reduce(sumArray) +
four.reduce(sumArray) +
five.reduce(sumArray) +
six.reduce(sumArray) +
seven.reduce(sumArray) +
eight.reduce(sumArray) +
nine.reduce(sumArray)
);
return gridSum
};
export default sumTheArrayGrid;