about | help | code help+videos | done | prefs |
Write a method that finds the total of all the values in an integer array, but each value is either added to the total or subtracted from the total based on a Boolean array. If the i-th position in the Boolean array is true, then add the i-th number in the integer array to the total. However, if the i-th position in the Boolean array is false, subtract the i-th number in the integer array from the total. As a pre-condition, you may assume that the length of the integer array is the same as the length of the Boolean array. Both arrays WILL be the same length, but they could otherwise have any length, including a length of zero. Look at the test data for examples. dec18_2017_APSLHL_addOrSubtract([4], [true]) → 4 dec18_2017_APSLHL_addOrSubtract([5, 7, 3, 2], [true, true, false, true]) → 11 dec18_2017_APSLHL_addOrSubtract([5, 7, 3, 2], [false, false, false, false]) → -17 ...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: 290
Copyright Nick Parlante 2017 - privacy