Geometry 1: Length of Line Segment

Published by Mateusz Mędrowski in

Write a function that takes coordinates of two points on a two-dimensional plane and returns the length of the line segment connecting those two points.

Examples

lineLength(arr[0]={15, 7}, arr[1]={22, 11}) ➞ 8.06

lineLength(arr[0]={0, 0}, arr[1]={0, 0}) ➞ 0

lineLength(arr[0]={0, 0}, arr[1]={1, 1}) ➞ 1.41

Notes

  • The numbers in the argument array can be positive or negative.
  • The order of the given numbers is X, Y.
  • There is 0.1 tolerance so you don't need to round your result.
  • This challenge is easier than it looks.
Watch a quick demo on how Edabit works.