1. How far apart are two fruits?
Draw each fruit as a dot: x = sweetness, y = weight. Similar fruits sit close together. The straight-line gap between two dots is the Euclidean distance — Pythagoras from Class 8!
distance = √((x1 - x2)² + (y1 - y2)²)
The same idea works with any number of features: for each feature, subtract, square, add them all up, then take the square root.
[0, 0]to[3, 4]→ √(9 + 16) = 5
const a = [0, 0];
const b = [3, 4];
const d = Math.sqrt((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2);
console.log(d);
Challenge: Euclidean distance
Write distance(a, b) where a and b are arrays of the same length (any length: 2, 3, …). Return the Euclidean distance: the square root of the sum of squared differences.