Why not try diff? For example, what does
do? TRY IT! What is distance? Does that give you something you might be able to work with? Does it get you closer to the goal that you need to achieve?
What if you then squared the elements of that array? Again, THINK! TRY IT!
Suppose you now used sum on the result?
what does that represent? Now, again, what is the distance you are trying to achieve? Would a sqrt help here? TRY IT!
When you have a difficult problem, break it into small pieces. Try to move towards the goal you want. Look for functions that will help you to acheive that goal. While it is often unlikely that you will find one magic function that does exactly what you want, it is also the case that very often, you can find several functions that will get you there when taken in combination.