Ad
Code
Diff
  • 4
    • function relativeNumbers(a, b) {
    • let arrOne = [];
    • let arrTwo = [];
    • for (let i = 2; i < 10; i++) {
    • if (a % i === 0 && a !== i) {
    • arrOne.push(i);
    • }
    • if(b % i === 0 && b !== i){
    • arrTwo.push(i)
    • }
    • }
    • for(let i = 0; i < arrOne.length; i++){
    • for(let j = 0; j < arrTwo.length; j++){
    • if(arrOne[i] === arrTwo[j]){
    • return "non relative"
    • }else return "relative"
    • }
    • }
    • }
    • 4

In this kata there will be two inputs.Your task is to determine whether relative numbers are or are not, if are relative numbers then return relative and if not non relative.

Relative numbers - integers that have no common divisors other than 1 and itself.

Example: relativeNumbers(8, 9):
The number 8 has 2,4 divisors;
The number 9 has 3 divisor;
Due to the fact that the numbers 8 and 9 do not have common divisors, they are relative numbers

function relativeNumbers(a, b) {
  let arrOne = [];
  let arrTwo = [];
  for (let i = 2; i < 10; i++) {
    if (a % i === 0 && a !== i) {
      arrOne.push(i);
    }
    if(b % i === 0 && b !== i){
        arrTwo.push(i)
    }
  }
  for(let i = 0; i < arrOne.length; i++){
    for(let j = 0; j < arrTwo.length; j++){
        if(arrOne[i] === arrTwo[j]){
            return "non relative"
        }else return "relative"
    }
  }
}
Code
Diff
  • function findMax(arr){
        let max = arr[0];
        for(let  i = 0; i < arr.length; i++){
            if(max < arr[i]){
                max = arr[i];
            }
        }
        return max;
    }
    
    • const findMax = arr => Math.max(...arr);
    • function findMax(arr){
    • let max = arr[0];
    • for(let i = 0; i < arr.length; i++){
    • if(max < arr[i]){
    • max = arr[i];
    • }
    • }
    • return max;
    • }