Last active
June 2, 2017 14:28
-
-
Save rodpoblete/fe58e08eccfa9ae0e9a4c938e311a6dc to your computer and use it in GitHub Desktop.
Busca y elimina valores de un array - FCC [255]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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