index.js
function binaddone(bin){
  var len = bin.length;
  var result = new Array(len + 1);
  var c = true;   // carry bit
  var i = len;   // i points at the bit in bin one after the untouched bit
  while(c && (i > 0)){
    i--;
    c = bin[i];
    result[i+1] = !c;
  }
  if(i){
    // Return remaining untouched bin concatenated with the touched bits
    return bin.slice(0, i).concat(result.slice(i+1));
  }else{
    if(c){
      // Return full result with carry as prefix
      result[0] = true;
      return result;
    }else{
      // Return result without carry
      return result.slice(1);
    }
  }
}
function binaddone(bin){
  var len = bin.length;
  var result = new Array(len + 1);
  var c = true;   // carry bit
  var i = len;   // i points at the bit in bin one after the untouched bit
  while(c && (i > 0)){
    i--;
    c = bin[i];
    result[i+1] = !c;
  }
  if(i){
    // Return remaining untouched bin concatenated with the touched bits
    return bin.slice(0, i).concat(result.slice(i+1));
  }else{
    if(c){
      // Return full result with carry as prefix
      result[0] = true;
      return result;
    }else{
      // Return result without carry
      return result.slice(1);
    }
  }
}
function binaddone ( bin ) { var len = bin . length ; var result = new Array ( len + 1 ) ; var c = true ; // carry bit var i = len ; // i points at the bit in bin one after the untouched bit while ( c && ( i > 0 ) ) { i -- ; c = bin [ i ] ; result [ i + 1 ] = ! c ; } if ( i ) { // Return remaining untouched bin concatenated with the touched bits return bin . slice ( 0 , i ) . concat ( result . slice ( i + 1 ) ) ; } else { if ( c ) { // Return full result with carry as prefix result [ 0 ] = true ; return result ; } else { // Return result without carry return result . slice ( 1 ) ; } } }
Addition of 1 to a binary array
Addition of 1 to a binary array