Last active
December 16, 2018 21:03
-
-
Save darya-makarenko/59d9d1c87116b17bbe59534b82ebad0d 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
puts "Enter the elements of array: (f.e. 1 2 3 4)" | |
arr = gets.chomp.split.map(&:to_i) | |
#if the element is positive it is replaced with the smallest element | |
#otherwise it remains untouched | |
min_element = arr.min | |
arr.collect! {|x| x > 0 ? min_element : x } | |
puts "The result array: #{arr.join(" ")}" |
aya-soft
commented
Nov 28, 2018
- arr.max считается многократно
- вроде как просили min, а не max по заданию
- как использовать тут тернарный оператор вместо if?
- как склеить массив через пробел?
🥇
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment