There was an error while loading. Please reload this page.
1 parent 759e81d commit 376a67cCopy full SHA for 376a67c
maths/abs.js
@@ -0,0 +1,26 @@
1
+/*
2
+ author: PatOnTheBack
3
+ license: GPL-3.0 or later
4
+
5
+ Modified from:
6
+ https://github.com/TheAlgorithms/Python/blob/master/maths/abs.py
7
8
+ This script will find the absolute value of a number.
9
10
+ More about absolute values:
11
+ https://en.wikipedia.org/wiki/Absolute_value
12
+*/
13
14
+function abs_val(num) {
15
+ // Find absolute value of `num`.
16
+ "use strict";
17
+ if (num < 0) {
18
+ return -num
19
+ }
20
+ // Executes if condition is not met.
21
+ return num
22
+}
23
24
+// Run `abs` function to find absolute value of two numbers.
25
+console.log("The absolute value of -34 is " + abs_val(-34));
26
+console.log("The absolute value of 34 is " + abs_val(34));
0 commit comments