Skip to main content

Filter

OtraEsta seria otra opción

    function moveZeros(arr) {
      let arr0 = arr.filter (e => e !== 0)
      let arr1 = arr.filter (cero => cero === 0);
      return [...arr0, ...arr1];
    }  
    moveZeros([false,1,0,1,2,0,1,3,"a"])

}
moveZeros([false,1,0,1,2,0,1,3,"a"]) Te dejo la documentación oficial:

Array.prototype.filter()

Filter

Otra opción

function moveZeros(arr) {
let arr0 = arr.filter (e => e !== 0)
let arr1 = arr.filter (cero => cero === 0);
return [...arr0, ...arr1];

}
moveZeros([false,1,0,1,2,0,1,3,"a"])

Array.prototype.filter()

Filter

Esta seria otra opción

    function moveZeros(arr){
      let arr0 = arr.filter (e => e !== 0)
      let arr1 = arr.filter (cero => cero === 0);
      return [...arr0, ...arr1];
    }  
    moveZeros([false,1,0,1,2,0,1,3,"a"])

Te dejo la documentación oficial:

Array.prototype.filter()

Origen Enlace

Filter

Otra opción

function moveZeros(arr) {
let arr0 = arr.filter (e => e !== 0)
let arr1 = arr.filter (cero => cero === 0);
return [...arr0, ...arr1];

}
moveZeros([false,1,0,1,2,0,1,3,"a"])

Array.prototype.filter()