find the midpoint between two points in javascript

Here's one way to find the midpoint between two points in JavaScript:

index.tsx
function midpoint(point1, point2) {
  return [(point1[0] + point2[0]) / 2, (point1[1] + point2[1]) / 2];
}

// Example usage:
let pointA = [0, 0];
let pointB = [4, 8];
let pointM = midpoint(pointA, pointB);
console.log(pointM); // [2, 4]
238 chars
10 lines

This function takes two points as input arguments, with each point represented as an array of x and y coordinates. It calculates the midpoint between the two points by averaging their x and y values separately, and then returning a new array with the calculated midpoint coordinates. Finally, we can call the function with two example points and log the resulting midpoint to the console.

gistlibby LogSnag