CodeWars/comparingArrays.js
// check if value of array 2 is equal to all values of array 1 squared
check if value of array 2 is equal to all values of array 1 squared
check if value of array 2 is equal to all values of array 1 squared
function comp(array1, array2){
  if(array1 === null || array2 === null)
    return false;
  array1.sort((a,b) => a - b);
  array2.sort((a,b) => a - b);
  for(let i = 0; i < array1.length; i++){
    let squared = array1[i] * array1[i];
    if(squared !== array2[i])
      return false;
  } 
return true;
}
function comp ( array1 , array2 ) { if ( array1 === null || array2 === null ) return false ; array1 . sort ( ( a , b ) => a - b ) ; array2 . sort ( ( a , b ) => a - b ) ; for ( let i = 0 ; i < array1 . length ; i ++ ) { let squared = array1 [ i ] * array1 [ i ] ; if ( squared !== array2 [ i ] ) return false ; } return true ; }
check if value of array 2 is equal to all values of array 1 squared
check if value of array 2 is equal to all values of array 1 squared
// if either array is null, return false // begin by sorting our arrays(ascending) // loop through our array checking each element  // if squared is not equal to the value at i for array2 return false // we exit the for loop if it is true