fork download
  1. // iterative
  2. function getAlter(arr){
  3. let res = [];
  4.  
  5. for(i=0;i<arr.length;i+=2){
  6. res.push(arr[i]);
  7. }
  8. return res;
  9. }
  10. const arr = [10,20,30,40,50];
  11. const res = getAlter(arr);
  12. console.log(res.join(" "));
  13.  
Success #stdin #stdout 0.03s 18776KB
stdin
Standard input is empty
stdout
10 30 50