Skip to content

Instantly share code, notes, and snippets.

@darya-makarenko
Last active December 16, 2018 21:03
Show Gist options
  • Save darya-makarenko/59d9d1c87116b17bbe59534b82ebad0d to your computer and use it in GitHub Desktop.
Save darya-makarenko/59d9d1c87116b17bbe59534b82ebad0d to your computer and use it in GitHub Desktop.
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
Copy link

  1. arr.max считается многократно
  2. вроде как просили min, а не max по заданию
  3. как использовать тут тернарный оператор вместо if?
  4. как склеить массив через пробел?

@aya-soft
Copy link

🥇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment