Last active
March 20, 2017 14:19
-
-
Save fee1good/0884d6575b2d1e13ae5c38ff35d9b93e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def monotonic? (arr) | |
p arr.length | |
arr.each_index do |i| | |
if arr.length - 1 == i || arr.length == 0 | |
p 'debug' | |
break | |
else | |
if arr[i + 1] - arr[i] == 1 | |
return true | |
else | |
return false | |
end | |
end | |
end | |
end | |
p monotonic?([]) # почему-то возвращает []. Я ожидаю, что выведет debug, т.к. длина массива равна нулю. Магия какая-то. | |
p monotonic?([1]) # возвращает debug, что верно, и какой-то nil, откуда он взялся? | |
# ➜ ruby-classes-victor git:(master) ✗ ruby num.rb | |
# "debug" | |
# nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment