function proposedNewGatesAreInvalid(dtos) {
  for (let i = 0; i < dtos.length; i++) {

    let noExpectedQubits = 0;
    let targets = [];
    let controls = [];

    if (Object.prototype.hasOwnProperty.call(dtos[i], "targets")) {
      targets = dtos[i]["targets"];
      noExpectedQubits += targets.length;
    }

    if (Object.prototype.hasOwnProperty.call(dtos[i], "controls")) {
      controls = dtos[i]["controls"];
      noExpectedQubits += controls.length;
    }

    let distinctQbits = [...targets, ...controls]
      // x - item in array
      // i - index of item
      // a - array reference
      .filter((x, i, a) => a.indexOf(x) == i);

    if (distinctQbits.length != noExpectedQubits) return true;
  }
  return false; 
}
// distinct qubits for each target and each control 
distinct qubits for each target and each control
distinct qubits for each target and each control
function proposedNewGatesAreInvalid(dtos) {
  for (let i = 0; i < dtos.length; i++) {
    let noExpectedQubits = 0;
    let targets = [];
    let controls = [];
    if (Object.prototype.hasOwnProperty.call(dtos[i], "targets")) {
      targets = dtos[i]["targets"];
      noExpectedQubits += targets.length;
    }
    if (Object.prototype.hasOwnProperty.call(dtos[i], "controls")) {
      controls = dtos[i]["controls"];
      noExpectedQubits += controls.length;
    }
    let distinctQbits = [...targets, ...controls]
      .filter((x, i, a) => a.indexOf(x) == i);
    if (distinctQbits.length != noExpectedQubits) return true;
  }
  return false; 
}
function proposedNewGatesAreInvalid ( dtos ) { for ( let i = 0 ; i < dtos . length ; i ++ ) { let noExpectedQubits = 0 ; let targets = [ ] ; let controls = [ ] ; if ( Object . prototype . hasOwnProperty . call ( dtos [ i ] , "targets" ) ) { targets = dtos [ i ] [ "targets" ] ; noExpectedQubits += targets . length ; } if ( Object . prototype . hasOwnProperty . call ( dtos [ i ] , "controls" ) ) { controls = dtos [ i ] [ "controls" ] ; noExpectedQubits += controls . length ; } let distinctQbits = [ ... targets , ... controls ] . filter ( ( x , i , a ) => a . indexOf ( x ) == i ) ; if ( distinctQbits . length != noExpectedQubits ) return true ; } return false ; }
distinct qubits for each target and each control
distinct qubits for each target and each control
// x - item in array // i - index of item // a - array reference