Recreating the abs() Function

Published by Robotics and coding in

The abs function returns the absolute value of a number. This means that it returns a number's positive value. You can think of it as the distance away from zero.

Create a function that recreates this functionality.

Examples

absolute(-5) ➞ 5

absolute(-3.14) ➞ 3.14

absolute(250) ➞ 250

Notes

Tests will only include valid numbers.

Watch a quick demo on how Edabit works.