Skip to content

Instantly share code, notes, and snippets.

@McLarenCollege
Last active September 19, 2022 03:43
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/4700168d2ef978585933f2e338934448 to your computer and use it in GitHub Desktop.
Save McLarenCollege/4700168d2ef978585933f2e338934448 to your computer and use it in GitHub Desktop.
Exercise : Convert False To True

Given an array of booleans change any false values to true that occur before the first true value.

function falseToTrue(booleans){
  // write your code here
}

let bools1 = [false, false, false, true, false, false, true];
falseToTrue(bools1);
console.log(bools1); // should print [true, true, true, true, false, false, true]

let bools2 = [false, false, false];
falseToTrue(bools2);
console.log(bools2);// should print [true, true, true]

let bools3 = [true, false, true];
falseToTrue(bools3);
console.log(bools3);// should print [true, false, true]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment