8 kyu
Compare within margin
6,160 of 15,889ITSOES
Description:
Create a function close_compare
that accepts 3 parameters: a
, b
, and an optional margin
. The function should return whether a
is lower than, close to, or higher than b
.
Please note the following:
- When
a
is close tob
, return0
.- For this challenge,
a
is considered "close to"b
ifmargin
is greater than or equal to the absolute distance betweena
andb
.
- For this challenge,
Otherwise...
When
a
is less thanb
, return-1
.When
a
is greater thanb
, return1
.
If margin
is not given, treat it as if it were zero.
Assume: margin >= 0
Tip: Some languages have a way to make parameters optional.
Example 1
If a = 3
, b = 5
, and margin = 3
, then close_compare(a, b, margin)
should return 0
.
This is because a
and b
are no more than 3 numbers apart.
Example 2
If a = 3
, b = 5
, and margin = 0
, then close_compare(a, b, margin)
should return -1
.
This is because the distance between a
and b
is greater than 0, and a
is less than b
.
Fundamentals
Logic
Similar Kata:
Stats:
Created | Nov 13, 2015 |
Published | Aug 24, 2016 |
Warriors Trained | 28164 |
Total Skips | 1528 |
Total Code Submissions | 59295 |
Total Times Completed | 15889 |
Python Completions | 6160 |
JavaScript Completions | 4916 |
Ruby Completions | 428 |
C# Completions | 1145 |
C Completions | 1172 |
Java Completions | 1466 |
Julia Completions | 36 |
Rust Completions | 339 |
Go Completions | 812 |
CoffeeScript Completions | 8 |
Scala Completions | 13 |
Total Stars | 238 |
% of votes with a positive feedback rating | 85% of 1962 |
Total "Very Satisfied" Votes | 1492 |
Total "Somewhat Satisfied" Votes | 337 |
Total "Not Satisfied" Votes | 133 |
Total Rank Assessments | 9 |
Average Assessed Rank | 7 kyu |
Highest Assessed Rank | 7 kyu |
Lowest Assessed Rank | 8 kyu |