coprimeWith method

bool coprimeWith(
  1. int number
)

Check if this number is coprime with the argument number

Implementation

bool coprimeWith(int number){
  List<int> myFactors = this.factors();
  List<int> numberFactors = number.factors();
  //Find common factors
  bool factorsInCommon = false;
  int iterator = 1;
  while(iterator < myFactors.length && factorsInCommon == false){
    if(numberFactors.indexOf(myFactors[iterator]) != -1){
      //Found a common factor it is not coprime
      factorsInCommon = true;
    }
    iterator++;
  }
  //Number is prime if it does not have common factors
  return !factorsInCommon;
}