사랑하애오

솔루션

const solution = (dots) => {
  const getInclination = ([[x1, y1], [x2, y2]]) =>
    x2 !== x1 ? (y2 - y1) / (x2 - x1) : Infinity;

  const isParallel = (line1, line2) =>
    getInclination(line1) === getInclination(line2);

  const answer = dots.some((dot) => {
    const line1 = [dots[0], dot];
    const line2 = dots.filter((dot) => !line1.includes(dot));
    return isParallel(line1, line2);
  })
    ? 1
    : 0;
  console.log(answer);

  return answer;
};

솔루션

const solution = (dots) => {
  const calculateSlope = (arr1, arr2) => {
    return (arr2[1] - arr1[1]) / (arr2[0] - arr1[0]);
  };

  if (calculateSlope(dots[0], dots[1]) === calculateSlope(dots[2], dots[3])) {
    return 1;
  } else if (
    calculateSlope(dots[0], dots[2]) === calculateSlope(dots[1], dots[3])
  ) {
    return 1;
  } else if (
    calculateSlope(dots[0], dots[3]) === calculateSlope(dots[1], dots[2])
  ) {
    return 1;
  } else {
    return 0;
  }
};
profile

사랑하애오

@사랑하애

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!