forked from TheAlgorithms/JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathabs.js
More file actions
26 lines (21 loc) · 643 Bytes
/
abs.js
File metadata and controls
26 lines (21 loc) · 643 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/*
author: PatOnTheBack
license: GPL-3.0 or later
Modified from:
https://github.com/TheAlgorithms/Python/blob/master/maths/abs.py
This script will find the absolute value of a number.
More about absolute values:
https://en.wikipedia.org/wiki/Absolute_value
*/
function absVal (num) {
// Find absolute value of `num`.
'use strict'
if (num < 0) {
return -num
}
// Executes if condition is not met.
return num
}
// Run `abs` function to find absolute value of two numbers.
console.log('The absolute value of -34 is ' + absVal(-34))
console.log('The absolute value of 34 is ' + absVal(34))