Last active
December 22, 2018 20:35
-
-
Save shamritskiy3468/b03c5c0d6d6114364652e681a439330b to your computer and use it in GitHub Desktop.
Task5
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 generate_array(size) | |
array = [] | |
size.to_i.times { array << rand(-10..20) } | |
array | |
end | |
#have some questions accroding to this task (probably, it can be done with 'each'?!) | |
def insert_zeros_to_array(array) | |
i = 0 | |
while(i < array.size) do | |
if array[i] > 0 | |
array.insert(i, 0) | |
i += 2 | |
end | |
i += 1 | |
end | |
array | |
end | |
puts "Enter Array size: " | |
size = gets.chomp | |
start_array = generate_array(size) | |
puts "Start Array = #{start_array.join(" ~ ")} " | |
result = insert_zeros_to_array(start_array) | |
puts "Result Array = #{result.join(" ~ ")} " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Тут мы из одного массива мы пытаемся сделать другой. А если метод
flatten
использовать, какое решение получится?