about | help | code help+videos | done | prefs |
Write a method that finds the 'total' of all the numbers in the array 'nums' by either adding each number to the total or subtracting it from the total. You add the number if the Boolean value in array 'add' is "true" in the position that corresponds to the number in 'nums' array. If the Boolean value is "false" then subtract the number from the total. As a precondition you may assume that 'nums' and 'add' have the same number of elements. Note that the arrays could be empty, in which case you simply return zero. feb_22_2019_SLHL_addOrSubtract([92, 42, 48, 0, 0, 2], [true, false, false, true, false, true]) → 4 feb_22_2019_SLHL_addOrSubtract([92, 42, 48, 0, 0, 2], [false, false, true, true, false, true]) → -84 feb_22_2019_SLHL_addOrSubtract([6, 5, 4, 3, 2, 1], [true, false, true, false, false, false]) → -1 ...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