DEV Community

Discussion on: Daily Challenge #213 - Are they the "same"?

Collapse
 
sabbin profile image
Sabin Pandelovitch • Edited

JS solution

const comp = (a, b) => {
  if (
    a === null ||
    b === null ||
    a.length === 0 ||
    b.length === 0 ||
    a.length !== b.length
  ) {
    return false;
  }

  let status = true;
  let i = 0;
  while (status && i < a.length) {
    status = b.indexOf(Math.pow(a[i],2)) > -1
    i++;
  }

  return status;
};

*fixed