code.cpp 422 B

1234567891011121314
  1. /* Create a function that goes through the array, incrementing
  2. * (+1) for each odd number and decrementing (-1)
  3. * for each even number.
  4. * ex. transform([1, 2, 3, 4, 5]) ➞ [2, 1, 4, 3, 6]
  5. */
  6. std::vector<int> transform(std::vector<int> arr) {
  7. for(int i = 0;i<arr.size();i++){
  8. // evaluate if even, -1 if even
  9. if(arr[i]%2 == 0){arr[i]-=1;}
  10. // evaluate if odd, +1 if odd
  11. else arr[i]+=1;
  12. }
  13. return arr;
  14. }