Skip to content

Instantly share code, notes, and snippets.

@McLarenCollege
Last active September 12, 2022 09:39
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 McLarenCollege/fa837f2a1483bd5b14b8c863827ae830 to your computer and use it in GitHub Desktop.
Save McLarenCollege/fa837f2a1483bd5b14b8c863827ae830 to your computer and use it in GitHub Desktop.
Count Trues Part1

Count trues before first false

Given an array consisting of true and false values, write a function that returns the number of true values present before the first false value using a while loop. If the array does not contain any false value return the number of true values.

function numberOfTrues(booleans){
// write your code here
}
console.log(numberOfTrues([true, true, false, false, true, true]));// 2
console.log(numberOfTrues([false, true, false, false, true, true]));// 0
console.log(numberOfTrues([true, true, true, true, true, true]));// 6
console.log(numberOfTrues([]));// 0
console.log(numberOfTrues([false, false, false]));// 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment