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
class Games | |
attr_accessor :array_of_score | |
def initialize(array_of_score) | |
@array_of_score = array_of_score | |
end | |
def check_attributes(rival) | |
return 'wrong attributes' unless @array_of_score.is_a?(Array) && | |
rival.is_a?(Array) |
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
class String | |
def palindrome? | |
self.downcase == self.downcase.reverse | |
end | |
end | |
puts "erere".palindrome? # true | |
puts "ror5".palindrome? # false | |
str3 = 'fdsf fdJJfd ajk hlj fqjqfpot otirn dfsdl dskj vcbn cx' | |
puts str3.palindrome? # false | |
str4 = 'xc nbcv jksd ldsfd nrito otirn dfsdl dskj vcbn cx' |
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
def count_words(str) | |
str.split.length | |
end | |
srt2 = 'fdsf fdsfd ajk hlj fqjqfpot otirn dfsdl dskj vcbn cx' | |
puts count_words srt2 |
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
def sort_string(str) | |
str.split.sort_by(&:length).join(' ') | |
end | |
srt1 = 'fdsf fdsfd ajk hlj fqjqfpot otirn dfsdl dskj vcbn cx' | |
puts sort_string srt1 |
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
numbers6 = [18, 234, 74, 47, -1163, -15, -1, 0, 71, 5143, 36] | |
puts numbers6.sort #immutable number_6 | |
puts numbers6.sort! #mutable number_6 |
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
print a = [1, 2, -2, 9, -3, -8, 4, 5, -6, 7, -8] | |
print a.flat_map { |elem| elem > 0 ? [a[0], elem] : elem } | |
print a.reduce([]) { |temp, i| temp.push(a[0]) if i > 0; temp.push(i) } | |
def add_before_positive(arr, f = arr.first) | |
arr.map.with_index do |elem, i| | |
if i > 0 && elem > 0 | |
arr_cut = arr.slice!(i..-1) |
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
def left_rotate(arr) | |
arr.push(arr.shift) | |
end | |
numbers4 = [18, 234, 74, 47, 1163, -15, -1, 0, 71, 5143, 36] | |
p left_rotate numbers4 |
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
def change_positive_on_first_elem(num) | |
m = num.min | |
num.map { |n| n > 0 ? m : n } | |
end | |
numbers3 = [180, 204, 154, -167, -163, 154, -110, -171, -143, -196] | |
puts change_positive_on_first_elem numbers3 |
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
def highest_student(height, surnames) | |
surnames[height.index(height.max)] | |
end | |
height = [180, 204, 154, 167, 163, 154, 110, 171, 143, 196] | |
students = ['Dziatlov', 'Smith)', 'Borakov', 'Smirnov', 'Kot', 'Gorshenia', | |
'Sapozhnikav', 'Landay', 'Tolstoy', 'Mihailin'] | |
puts highest_student height, students |
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
def check_attributes(your, rival) | |
return 'wrong attributes' unless your.is_a?(Array) && | |
rival.is_a?(Array) | |
(rival + your).each do |i| | |
return 'wrong type in Array' unless i.is_a?(Integer) && i >= 0 | |
end | |
'different count game' unless rival.length == your.length | |
end | |
def win_or_lost_game(your, rival) |
NewerOlder