Skip to content

Instantly share code, notes, and snippets.

@rodpoblete
Last active June 2, 2017 14:28
Show Gist options
  • Save rodpoblete/fe58e08eccfa9ae0e9a4c938e311a6dc to your computer and use it in GitHub Desktop.
Save rodpoblete/fe58e08eccfa9ae0e9a4c938e311a6dc to your computer and use it in GitHub Desktop.
Busca y elimina valores de un array - FCC [255]
function destroyer(arr) {
var temp = []; // Creo un array temporal vacio
for (var i = 1; i < arguments.length; i++) // ciclo para recorrer el array
temp.push(arguments[i]); // traspado valores al array temporal
return arr.filter( function(remove) { // funcion filter filtra el array original con un callback
return temp.indexOf(remove) < 0; // devuelve true o false si el valor en el indice corresponde
});
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3); // [1, 1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment