code.cpp 714 B

12345678910111213141516171819
  1. /* This is a reverse coding challenge.
  2. * Normally you're given explicit directions with how to create a function.
  3. * Here, you must generate your own function to satisfy the relationship
  4. * between the inputs and outputs.
  5. * Your task is to create a function that, when fed the inputs below,
  6. * produce the sample outputs shown.
  7. */
  8. std::vector<int> mysteryFunc(std::vector<int> arr, int num) {
  9. std::vector<int> remaindarray;
  10. // THE SECRET: its an array output of the remainders from input array.
  11. // loop through the array
  12. for(int i=0;i<arr.size();i++){
  13. // check divisibility of each element. then store remainder into new array.
  14. remaindarray.push_back(arr[i]%num);
  15. }
  16. return remaindarray;
  17. }