-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharrayPlusArray.js
More file actions
35 lines (27 loc) · 969 Bytes
/
arrayPlusArray.js
File metadata and controls
35 lines (27 loc) · 969 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
/*
Codewars 8 Kyu Array plus array
URL: https://www.codewars.com/kata/5a2be17aee1aaefe2a000151
I'm new to coding and now I want to get the sum of two arrays... Actually the sum of all their elements. I'll appreciate for your help.
P.S. Each array includes only integer numbers. Output is a number too.
*/
// function arrayPlusArray(arr1, arr2) {
// let total = 0;
// for(let i = 0; i < arr1.length; i++) {
// total += arr1[i];
// }
// for(let i = 0; i < arr2.length; i++) {
// total += arr2[i];
// }
// return total;
// }
// function arrayPlusArray(arr1, arr2) {
// let total = 0;
// for(let i = 0; i < arguments.length; i++) {
// for(let j = 0; j < arguments[i].length; j++){
// total += arguments[i][j];
// }
// }
// return total;
// }
const arrayPlusArray = (arr1, arr2) => arr1.concat(arr2).reduce((accu, curr) => accu + curr);
console.log(arrayPlusArray([1,2,3], [4,5,6]))