Sum
Lesson 12 of 24 in Coddy's Golang Challenges - Level 1 course.
Challenge
EasyWe have an array like this: [2, 4, 6, 7, 8, 8, 9].
Write a function that calculates the sum of the first, the middle, and the last elements of a given array.
If the array doesn't have a middle element that divides the slice into two equal parts, return -1.
For our example, we should calculate the sum of 2 + 7 + 9 = 18.
Explanation:
- [2] - the first element
- [7] - the middle element: [2, 4, 6] 7 [8, 8, 9]
- [9] - the last element.
Try it yourself
func calculateSum( ) {
}All lessons in Golang Challenges - Level 1
1Introduction
Introduction3Play with Slices & Arrays
Longest StringDouble Even NumbersSum Average Minimum and MaxSumEven & Odd NumbersSlice to Map Non Repeated Indices