Respuestas Ejercicio 43 (JS Julio)

Comparte tu respuesta del ejercicio 43.

function posPares(arr){
  return arr.filter((el,i)=>{if(i%2===0) return toString(el)});
}
console.log(posPares(["a", "b", "c"])) // ["a", "c"]
console.log(posPares([0, 1, 2, 3, 4])) // [0, 2, 4]
console.log(posPares([])) // []
function posPares(arr){
  let aux = []
  arr.filter((element,index) => {
    if(index%2===0){
      aux.push(element)
    } 
    });
    return aux;
}

Mi respuesta:

function posPares(myArray){
  return myArray.filter((item,index) => (index % 2 === 0));
}
// código de prueba
console.log(posPares(["a", "b", "c"])) // ["a", "c"]
console.log(posPares([0, 1, 2, 3, 4])) // [0, 2, 4]
console.log(posPares([])) // []

Buena noche:

function posPares(arr){
  return arr.filter((term, i) => (i % 2 === 0))
}
function posPares(arr){
    return arr.filter( item => !(arr.indexOf(item)&1) )
}
function posPares(arr){
    return(arr.filter((item,element) => (element%2 === 0)))
}

console.log(posPares(["a", "b", "c"]))
console.log(posPares([0, 1, 2, 3, 4]))
console.log(posPares([]))
const posPares = function(arr){
  return arr.filter(function(el, i){
      return i % 2 === 0;
  });
}
console.log(posPares(["a", "b", "c"])) // ["a", "c"]
console.log(posPares([0, 1, 2, 3, 4])) // [0, 2, 4]
console.log(posPares([])) // []

Buenas noches, esta es mi respuesta:

function posPares(arreglo){
return arreglo.filter( (num, index) => index % 2 === 0);
}
function posPares(arr){
  let arr2=[]
  arr.filter((elem,i) => { i % 2 === 0 ? arr2.push(elem) : elem})
  return arr2
}


console.log(posPares(["a", "b", "c"]))
console.log(posPares([0, 1, 2, 3, 4]))
console.log(posPares([]))
function posPares(A){
  return A.filter((elemento, i) =>
    (i%2===0) 
  )
}
// código de prueba
console.log(posPares(["a", "b", "c"])) // ["a", "c"]
console.log(posPares([0, 1, 2, 3, 4])) // [0, 2, 4]
console.log(posPares([])) // []
1 me gusta
const posPares = arr => arr.filter((ele, indi) => {if (indi % 2 === 0) return ele;});
function posPares(arreglo){
  let newArray = arreglo.filter((elemet, index) => index%2==0)
  return newArray
}
console.log(posPares(["a", "b", "c"])) // ["a", "c"]
console.log(posPares([0, 1, 2, 3, 4])) // [0, 2, 4]
console.log(posPares([])) // []

Mi respuesta:

function posPares(arr){
  return arr.filter((el,i)=>{if(i%2===0) return toString(el)});
}
console.log(posPares(["a", "b", "c"])) ;
console.log(posPares([0, 1, 2, 3, 4]));
console.log(posPares([]));

Mi código:

function posPares(x=[]){
  return x.filter((element,i) => (i % 2 === 0))
function posPares(arreglo){
    return(arreglo.filter((elemento,posicion) => (posicion %2 === 0)))
}

console.log(posPares(["a", "b", "c"]))
console.log(posPares([0, 1, 2, 3, 4]))
console.log(posPares([]))
1 me gusta
function posPares(array){
  
    return(array.filter((valor,elemento) => (elemento%2 === 0)));
    
}

console.log(posPares(["a", "b", "c"]))
console.log(posPares([0, 1, 2, 3, 4]))
console.log(posPares([]))

Buenas noches
esta es mi respuesta

const posPares = arr => arr.filter((el, idx) => {return idx%2===0})
const posPares = (arr) => arr.filter((a,i) => i%2===0);
// código de prueba
console.log(posPares(["a", "b", "c"])); // ["a", "c"]
console.log(posPares([0, 1, 2, 3, 4])); // [0, 2, 4]
console.log(posPares([])); // []

Mi solución: :man_technologist:

// escribe tu función acá
function posPares(values = []){
    const newValues = values.filter((value, i) => (i % 2 === 0));

    return newValues;
}

output:

[ 'a', 'c' ]
[ 0, 2, 4 ]
[]