I need to add together two arrays of numbers and print the result as a total number.
arr1 = [1, 2, 3]
arr2 = [4, 5, 6]
arr1 arr2
Just gives me = 1 2 3 4 5 6, but I want 21.
CodePudding user response:
you can use the sum
method
arr1 = [1, 2, 3]
arr2 = [4, 5, 6]
(arr1 arr2).sum
CodePudding user response:
This is another way
arr1 = [1, 2, 3]
arr2 = [4, 5, 6]
p (arr1 arr2).reduce(: )
Output
21