mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-06 09:28:26 +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
|
* @function absVal
|
||||||
license: GPL-3.0 or later
|
* @description This script will find the absolute value of a number.
|
||||||
|
* @param {Integer} num - The input integer
|
||||||
Modified from:
|
* @return {Integer} - Absolute number of num.
|
||||||
https://github.com/TheAlgorithms/Python/blob/master/maths/abs.py
|
* @see [Absolute_value](https://en.wikipedia.org/wiki/Absolute_value)
|
||||||
|
* @example absVal(-10) = 10
|
||||||
This script will find the absolute value of a number.
|
* @example absVal(50) = 50
|
||||||
|
* @example absVal(0) = 0
|
||||||
More about absolute values:
|
*/
|
||||||
https://en.wikipedia.org/wiki/Absolute_value
|
|
||||||
*/
|
|
||||||
|
|
||||||
const absVal = (num) => {
|
const absVal = (num) => {
|
||||||
// Find absolute value of `num`.
|
// Find absolute value of `num`.
|
||||||
|
@ -10,4 +10,9 @@ describe('absVal', () => {
|
|||||||
const absOfPositiveNumber = absVal(50)
|
const absOfPositiveNumber = absVal(50)
|
||||||
expect(absOfPositiveNumber).toBe(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