merge: Absolute value (#866)

This commit is contained in:
YATIN KATHURIA
2021-12-11 13:29:19 +05:30
committed by GitHub
parent 7560beb068
commit 4d55b40c9e
2 changed files with 15 additions and 12 deletions

View File

@ -1,14 +1,12 @@
/*
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) => {

View File

@ -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)
})
})