Skip to content

Instantly share code, notes, and snippets.

@mmloveaa
Created April 7, 2016 04:31
Show Gist options
  • Save mmloveaa/b318c1799c7fd28b935668ec5dd6a2e8 to your computer and use it in GitHub Desktop.
Save mmloveaa/b318c1799c7fd28b935668ec5dd6a2e8 to your computer and use it in GitHub Desktop.
FCC - slasher
function slasher(arr, howMany) {
console.log(arr.splice(0,howMany));
console.log(arr)
return arr.slice(howMany);
// it doesn't always pay to be first
// if(howMany > arr.length){
// return [];
//} else if (howMany===0){
// return arr;
//} else {
// return arr.slice(howMany, howMany+1);
//}
}
slasher([1, 2, 3], 2);
// slasher([1, 2, 3], 0);
// slasher([1, 2, 3], 2) should return [3].
// slasher([1, 2, 3], 0)
// should return [1, 2, 3].
// slasher([1, 2, 3], 9) should return [].
// slasher([1, 2, 3], 4) should return [].
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment