This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
<!DOCTYPE html>
|
||||
<!doctype html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
@@ -24,6 +24,18 @@
|
||||
</main>
|
||||
<script>
|
||||
'use strict';
|
||||
|
||||
const distance = ({ x: xOrigin, y: yOrigin }, { x: xDest, y: yDest }) => {
|
||||
return Math.sqrt((yDest - yOrigin) ** 2 + (xDest - xOrigin) ** 2);
|
||||
};
|
||||
|
||||
// RECOMMENDED without destructuring
|
||||
const getDistance = (origin, dest) => {
|
||||
return Math.sqrt((dest.y - origin.y) ** 2 + (dest.x - origin.x) ** 2);
|
||||
};
|
||||
|
||||
console.log('Die Distanz beträgt: ', distance({ x: 1, y: 1 }, { x: 5, y: 1 }));
|
||||
console.log('Die Distanz beträgt: ', getDistance({ x: 1, y: 1 }, { x: 5, y: 1 }));
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user