mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-06 01:18:23 +08:00
merge: Absolute value (#866)
This commit is contained in:
22
Maths/Abs.js
22
Maths/Abs.js
@ -1,15 +1,13 @@
|
||||
/*
|
||||
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
|
||||
* @description This script will find the absolute value of a number.
|
||||
* @param {Integer} num - The input integer
|
||||
* @return {Integer} - Absolute number of num.
|
||||
* @see [Absolute_value](https://en.wikipedia.org/wiki/Absolute_value)
|
||||
* @example absVal(-10) = 10
|
||||
* @example absVal(50) = 50
|
||||
* @example absVal(0) = 0
|
||||
*/
|
||||
|
||||
const absVal = (num) => {
|
||||
// Find absolute value of `num`.
|
||||
|
@ -10,4 +10,9 @@ describe('absVal', () => {
|
||||
const absOfPositiveNumber = absVal(50)
|
||||
expect(absOfPositiveNumber).toBe(50)
|
||||
})
|
||||
|
||||
it('should return an absolute value of a zero number', () => {
|
||||
const absOfPositiveNumber = absVal(0)
|
||||
expect(absOfPositiveNumber).toBe(0)
|
||||
})
|
||||
})
|
||||
|
Reference in New Issue
Block a user