Skip to content

Instantly share code, notes, and snippets.

@slopeofhope81
Created February 5, 2014 15:49
Show Gist options
  • Select an option

  • Save slopeofhope81/8826558 to your computer and use it in GitHub Desktop.

Select an option

Save slopeofhope81/8826558 to your computer and use it in GitHub Desktop.
Write a function countZeroes, which takes an array of numbers as its argument and returns the amount of zeroes that occur in it. Use reduce
Make the function abstract using reduce.
function countZeroes(numbers){
function count(total,num){
return total+(num ===0?1:0); <<===this is ternary equation!!!
}
return reduce(count, 0, numbers)
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment