Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Toggle All Booleans

Fundamentals: Part 1medium

Course · Section 2: JavaScript Fundamentals – Part 1 · Lecture 13: Basic Operators

Implement `toggleAll(arr)` returning a new array with the logical NOT of each element.

Sample tests

Input: toggleAll([true,false])
Output: [false,true]
Input: toggleAll([1,0])
Output: [false,true]

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Mutating the array instead of mapping to a new one.

Learning resources

  • MDN: Expressions and operators
Approach & explanation (try first)

map with !x returns a new array of negated truthiness for each element.

Loading...
⌘/Ctrl + Enter

Run your code to see results.