Skip to content

Instantly share code, notes, and snippets.

@rodpoblete
Last active May 29, 2017 21:01
Show Gist options
  • Save rodpoblete/5535d40b38ed20695bc1962627538ee2 to your computer and use it in GitHub Desktop.
Save rodpoblete/5535d40b38ed20695bc1962627538ee2 to your computer and use it in GitHub Desktop.
Devuelve elementos restantes de una matriz despues de cortar n elementos de la cabeza - FCC [252]
function slasher(arr, howMany) {
if (howMany === 0) // compara si el parametro de corte es cero
return arr; // retorna el array completo
else if (howMany > arr.length) // si el parametro de corte es mayor al largo del array
return []; // devuelve vacio, ya que es no es un valor valido
else
return arr.splice(howMany); // caso contrario devuelve el array con el elemento cortado howMany
}
slasher([1, 2, 3], 2); // [3]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment