aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gleam/int.gleam15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/gleam/int.gleam b/src/gleam/int.gleam
index 1a31c0c..f23f0f9 100644
--- a/src/gleam/int.gleam
+++ b/src/gleam/int.gleam
@@ -18,6 +18,21 @@ pub fn absolute_value(num: Int) -> Int {
}
}
+/// Returns the absolute distance of the inputs as a positive Int
+///
+/// ## Examples
+///
+/// > distance(-10, 10)
+/// 20
+///
+/// > distance(0.0, -2)
+/// 2
+///
+pub fn distance(a: Int, b: Int) -> Int {
+ a - b
+ |> absolute_value()
+}
+
/// Parses a given string as an int if possible.
///
/// ## Examples