sábado, 2 de julio de 2016

Seek And Destroy

Seek and Destroy:


You will be provided with an initial array (the first argument in the destroyer function), followed by one or more arguments. Remove all elements from the initial array that are of the same value as these argument

The solution:

function destroyer(arr) { args = Array.from(arguments); var nArray=[]; for(j=0;j<arr.length;j++){ var x=0; for(i=1;i<args.length;i++){ if (arr[j] !== args[i]){ x= x+1;  
if (x===args.length-1){ nArray.push(arr[j]); } } } } return nArray; } destroyer([1, 2, 3, 1, 2, 3], 2, 3);

No hay comentarios:

Publicar un comentario