fork download
  1. function getAlter(arr, idx, res){
  2. if(idx < arr.length){
  3. res.push(arr[idx]);
  4. getAlter(arr, idx + 2, res);
  5. }
  6. }
  7.  
  8. function getAltertwo(arr){
  9. let res = [];
  10. getAlter(arr, 0, res);
  11. return res;
  12. }
  13.  
  14. const arr = [10,20,30,40,50];
  15. let res = getAltertwo(arr);
  16. console.log(res);// your code goes here
Success #stdin #stdout 0.03s 18888KB
stdin
Standard input is empty
stdout
10,30,50