Skip to content

Instantly share code, notes, and snippets.

@joePichardo
Created December 10, 2015 05:51
Show Gist options
  • Save joePichardo/9c45bdd2a91a74936d25 to your computer and use it in GitHub Desktop.
Save joePichardo/9c45bdd2a91a74936d25 to your computer and use it in GitHub Desktop.
Return the remaining elements of an array after chopping off n elements from the head.
// Bonfire: Slasher Flick
// Author: @joepichardo
// Challenge: http://www.freecodecamp.com/challenges/bonfire-slasher-flick
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function slasher(arr, howMany) {
// it doesn't always pay to be first
//howMany is the number we must remove from our array of arr
//if howMany is larger than arr length return empty string
//else return array by the method slice
// we start at index "howMany" and goes all the way to the end or (arr.length)
if(howMany >= arr.length){
return [];
} else {
return arr.slice(howMany, arr.length);
}
}
slasher([1, 2, 3], 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment