Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions Maths/Abs.js
Original file line number Diff line number Diff line change
@@ -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`.
Expand Down
5 changes: 5 additions & 0 deletions Maths/test/Abs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})