Created
February 22, 2017 22:56
-
-
Save dmmfll/b085bb4290f51981cbbe121ee3f3e75a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
Untitled.txt | |
.ipynb_checkpoints/ | |
gist_url |
This file contains hidden or 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 element_index(element, my_array) | |
i = 0 | |
length = my_array.length | |
while i < length | |
guess = my_array[i] | |
# puts [guess == element, guess] | |
return i if guess == element | |
i += 1 | |
end | |
-1 | |
end | |
p element_index("b", ["a", "b", "c"]) | |
# should output 1 | |
p element_index("hello", ["a", "b", "c"]) | |
# should output -1 |
This file contains hidden or 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
(1..25).step(2).each do |n| | |
puts n ** 0.5 | |
end | |
(1..25).step(2).each do |n| | |
puts n | |
end | |
i = 1 | |
while i <= 25 | |
puts i ** 0.5 | |
i += 2 | |
end | |
i = 1 | |
odds = (1..25).step(2).to_a | |
puts odds | |
length = odds.length | |
while i < length | |
puts odds[i] ** 0.5 | |
i += 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment