How far apart
- O(1) · Trivial
- Free
- Python
- JavaScript
- operations
- comparisons
Problem
Write a function that takes two numbers and returns how far apart they are on the number line. From 3 to 10 there are 7, and from 10 to 3 there are 7 as well: the order you get them in doesn't matter and the answer is never negative.
If both numbers are the same, they are 0 apart.
Examples
3, 10 → 7
10, 3 → 7
-4, 6 → 10
Besides these, the challenge has hidden tests that are revealed when you submit your solution.
You start with this
Python
def distance(a, b):
passJavaScript
function distance(a, b) {
}Solve this challenge
It opens in your browser, with the editor and the tests. It is free and you do not need an account to start.