Skip to content

Commit 376a67c

Browse files
committed
Create abs.js
This script calculates absolute value.
1 parent 759e81d commit 376a67c

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

maths/abs.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)