Skip to content

Instantly share code, notes, and snippets.

@acalpixca
Created July 25, 2018 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acalpixca/d63a91dfbb493887a913f30269f0c9b7 to your computer and use it in GitHub Desktop.
Save acalpixca/d63a91dfbb493887a913f30269f0c9b7 to your computer and use it in GitHub Desktop.
cassidoo challenge 2018-07-24
/*
Given an int array, remove all leading zeros from the array.
removeLeading({0, 0, 0, 1, 0, 2, 3})
> 1 0 2 3
*/
function removeZeros(s) {
if (s.length<=0) {
return ([]);
}
else if (s[0]!=0) {
return(s);
}
else {
// Si no es recursivo, no mola ;-)
return (removeZeros(s.slice(1,s.length)));
}
}
console.log(removeZeros([0,0,1,2,3]));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment