Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.7.2
42 changes: 35 additions & 7 deletions test_skeleton.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ class TestSkeleton
# TestSkeleton.new.even_or_odd(0) should return "even"
# TestSkeleton.new.even_or_odd(-42) should return "even"
def even_or_odd(number)
# Your solution should be here
if number.even?
'even'
else
'odd'
end
end

# https://www.codewars.com/kata/5583090cbe83f4fd8c000051
Expand All @@ -21,7 +25,7 @@ def even_or_odd(number)
# TestSkeleton.new.reverse_array(348597) should return [7,9,5,8,4,3]
# TestSkeleton.new.reverse_array(0) should return [0]
def reverse_array(number)
# Your solution should be here
number.to_s.split('').map(&:to_i).reverse
end

# https://www.codewars.com/kata/554b4ac871d6813a03000035
Expand All @@ -36,7 +40,9 @@ def reverse_array(number)
# There will always be at least one number in the input string.
# Output string must be two numbers separated by a single space, and highest number is first.
def high_and_low(test_string)
# Your solution should be here
array_of_nums = test_string.split(' ').map(&:to_i)
array_of_min_max = array_of_nums.minmax
answer = array_of_min_max.reverse.join(" ")
end

# https://www.codewars.com/kata/5b16490986b6d336c900007d
Expand All @@ -49,7 +55,14 @@ def high_and_low(test_string)
# TestSkeleton.new.my_languages({"Hindi" => 60, "Dutch" => 93, "Greek" => 71}) should return ["Dutch", "Greek", "Hindi"]
# TestSkeleton.new.my_languages({"C++" => 50, "ASM" => 10, "Haskell" => 20}) should return []
def my_languages(hash)
# Your solution should be here
answer = []
arr = hash.sort {|a,b| b[1]<=>a[1]}
arr.each do |a|
if a[1].to_i >= 60
answer.append(a[0])
end
end
answer
end

# https://www.codewars.com/kata/563089b9b7be03472d00002b
Expand All @@ -62,7 +75,10 @@ def my_languages(hash)
# values_list = [1, 3, 4, 2]
# TestSkeleton.new.remove_array_elements(integer_list, values_list) should return [5, 6 ,7 ,8]
def remove_array_elements(source_array, values_array)
# Your solution should be here
for i in values_array
source_array.delete(i)
end
source_array
end

# https://www.codewars.com/kata/5b39e91ee7a2c103300018b3
Expand All @@ -72,7 +88,13 @@ def remove_array_elements(source_array, values_array)
# string = "alpha beta beta gamma gamma gamma delta alpha beta beta gamma gamma gamma delta"
# TestSkeleton.new.consecutive_duplicates(string) should return "alpha beta gamma delta alpha beta gamma delta"
def consecutive_duplicates(string)
# Your solution should be here
arr = string.split(' ')
arr.each_with_index do |val, index|
while arr[index] == arr[index+1] or arr[index] == arr[index-1]
arr.delete_at(index)
end
end
arr.join(' ')
end

# https://www.codewars.com/kata/56747fd5cb988479af000028
Expand All @@ -90,6 +112,12 @@ def consecutive_duplicates(string)
# Output:
# The middle character(s) of the word represented as a string.
def middle_chars(test_string)
# Your solution should be here
str_len = test_string.length
index = str_len / 2
if str_len.even?
test_string[index - 1] + test_string[index]
else
test_string[index]
end
end
end