Skip to content

Instantly share code, notes, and snippets.

@darya-makarenko
Last active December 16, 2018 21:04
Show Gist options
  • Save darya-makarenko/7f1c56149a9b41b8878364efb4086d71 to your computer and use it in GitHub Desktop.
Save darya-makarenko/7f1c56149a9b41b8878364efb4086d71 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)
#inserting the special value
#before every positive element
arr.map!{ |el| el > 0 ? [0, el] : el }
arr.flatten!
puts "The result array: #{arr.join(" ")}"
@aya-soft
Copy link

🥇 🥇

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