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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Form Validation</title> | |
<style> | |
body { | |
font-family: Arial, sans-serif; | |
max-width: 500px; |
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
tasks = [] | |
loop do | |
puts "\n1. Додати задачу" | |
puts "2. Показати задачі" | |
puts "3. Видалити задачу" | |
puts "4. Вийти" | |
print "\nОберіть опцію: " | |
choice = gets.chomp |
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
# Task 1: Find the most frequent element(s) | |
def most_frequent_elements(array) | |
frequency = Hash.new(0) | |
array.each { |num| frequency[num] += 1 } | |
max_freq = frequency.values.max | |
result = frequency.select { |_, freq| freq == max_freq }.keys | |
result |
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
# ruby_tasks.rb | |
# 1. Дано цілочисельний масив. Вивести елементи з парними індексами, а потім з непарними. | |
data = [1, 2, 3, 4, 5, 6] | |
p (data.each_with_index.select { |_, i| i.even? } + data.each_with_index.select { |_, i| i.odd? }).map(&:first) | |
# 2. Дано цілочисельний масив. Вивести елементи з непарними індексами, а потім з парними. | |
data = [1, 2, 3, 4, 5, 6] | |
p (data.each_with_index.select { |_, i| i.odd? } + data.each_with_index.select { |_, i| i.even? }).map(&:first) |