Skip to content

Instantly share code, notes, and snippets.

@SerhiiLihus
Created December 2, 2015 14:45
Show Gist options
  • Save SerhiiLihus/32eb9e331e58e5207e22 to your computer and use it in GitHub Desktop.
Save SerhiiLihus/32eb9e331e58e5207e22 to your computer and use it in GitHub Desktop.
Slasher Flick
// Bonfire: Slasher Flick
// Author: @serhiilihus
// Challenge: http://www.freecodecamp.com/challenges/bonfire-slasher-flick?solution=function%20slasher(arr%2C%20howMany)%20%7B%0A%20%20if%20(%20arr.length%20%3D%3D%3D%200%20)%20%7B%0A%20%20%20%20%20%20return%20arr%3B%0A%20%20%7D%20else%20if%20(%20howMany%20%3E%20arr.length%20)%20%7B%0A%20%20%20%20%20%20return%20%5B%5D%3B%0A%20%20%7D%20else%20arr.splice(0%2ChowMany)%3B%0A%20%20%0A%20%20return%20arr%3B%0A%7D%0A%0Aslasher(%5B1%2C%202%2C%203%5D%2C%202)%3B%0A
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function slasher(arr, howMany) {
if ( arr.length === 0 ) {
return arr;
} else if ( howMany > arr.length ) {
return [];
} else arr.splice(0,howMany);
return arr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment