// iterative
function getAlter(arr){
let res = [];
for(i=0;i<arr.length;i+=2){
res.push(arr[i]);
}
return res;
}
const arr = [10,20,30,40,50];
const res = getAlter(arr);
console.log(res.join(" "));
Ly8gaXRlcmF0aXZlCmZ1bmN0aW9uIGdldEFsdGVyKGFycil7CglsZXQgcmVzID0gW107CgkKCWZvcihpPTA7aTxhcnIubGVuZ3RoO2krPTIpewoJcmVzLnB1c2goYXJyW2ldKTsKIH0KIHJldHVybiByZXM7Cn0KY29uc3QgYXJyID0gWzEwLDIwLDMwLDQwLDUwXTsKY29uc3QgcmVzID0gZ2V0QWx0ZXIoYXJyKTsKY29uc29sZS5sb2cocmVzLmpvaW4oIiAiKSk7Cg==