about | help | code help+videos | done | prefs |
Write a method called Collapse2 that accepts an array of integers as a parameter and returns a new array containing the result of replacing each pair of integers with the sum of that pair. For example, if an array called nums contains the values {7, 2, 8, 9, 4, 13, 7, 1, 9, 10}, then the call to the method Collapse2 should return a new array containing {9, 17, 17, 8, 19}. The first pair from the original list 7 + 2 = 9 and so on. If the given array of numbers has an odd number of elements then place the last element into the new array. Collapse2([7, 2, 8, 9, 4, 13, 7, 1, 9, 10]) → [9, 17, 17, 8, 19] Collapse2([]) → [] Collapse2([2, 2]) → [4] ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Difficulty: 110
Copyright Nick Parlante 2017 - privacy