From 4d55b40c9ed5a140bc779c2507860f5f77971202 Mon Sep 17 00:00:00 2001 From: YATIN KATHURIA <47096348+Yatin-kathuria@users.noreply.github.com> Date: Sat, 11 Dec 2021 13:29:19 +0530 Subject: [PATCH] merge: Absolute value (#866) --- Maths/Abs.js | 22 ++++++++++------------ Maths/test/Abs.test.js | 5 +++++ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/Maths/Abs.js b/Maths/Abs.js index 4caa783ff..ed90edb34 100644 --- a/Maths/Abs.js +++ b/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`. diff --git a/Maths/test/Abs.test.js b/Maths/test/Abs.test.js index 116336f85..34143dfee 100644 --- a/Maths/test/Abs.test.js +++ b/Maths/test/Abs.test.js @@ -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) + }) })