title: Is there a simple way to swap 0 and 1 in an array
body: <p>I have a task where I need to swap the index values within an array.</p>
  
  <p>This is the code that I have written. I am kinda new to js, so it may be a bit off.</p>
  
  <pre><code>function swap(arr){
  for(let i = 0; i = arr.length; i++){
    if (arr[i] == 0){
      return arr[i] + 1
    }
    if (arr[i]== 1){
       return arr[i] - 1
    } 
    }else{
       return "only accepts 0 and 1"
    }
  }
  console.log(swap[[1,0,0],[0,1,0],[1,1,0]])
  </code></pre>
  
  <p>the <code>console.log</code> should return <code>[[0,1,1],[1,0,1],[0,0,1]]</code></p>