1. You are given 150 minutes to solve all the exercises. If you manage to solve them all ahead of time you can submit your answer to @ralibi in Slack privately.
2. For any exercise, you may submit more than one solution. We encourage you to write a solution that works first, then if you have time you can refine it and write another solution that works right.
3. You can solve the exercises in random order. Our suggestion is to solve the ones you deem easier first then move on to harder ones.
4. You may use Ruby Doc or API Dock. You may ask mentor to clarify about the question in any exercises, but you may not consult mentor or your friends on how to solve it. Googling and looking up at Stack Overflow for solutions are of course not permissible.
5. If you have finished all the exercises or if the time is up, submit your solutions in one file named "ruby_test_week_1-your_name.rb".
6. Good luck, have fun!
You are given a task to write a boolean expression that help HR to filter possible candidates. You will be given an object called candidate with sample data like this:
candidate.years_of_experience = 4
candidate.github_points = 293
candidate.languages_worked_with = ['C', 'Ruby', 'Python', 'Clojure']
candidate.applied_recently? = false
candidate.age = 26With requirements:
# 1. Candidate must have experience working with Ruby programming language
# 2. Candidate must have two or more years in working experience.
# However, if a candidate has less than two years experience,
# we can still hire him/her if he/she has great Github points (500 or more)
# 3. Candidate must be older than 15 years old
# 4. Candidate that has recently applied should not be considered
is_hired = # write your boolean expression hereWrite a method that when given two integers "a" and "b", will return the sum of cubes of every number from "a" to "b". (Cube of 3 is 27)
sum_of_cubes(1, 3) # return 36
sum_of_cubes(3, 4) # return 216Write a method that when given a sentence, it will return true if the sentence is a palindrome and return false otherwise.
palindrome?("Race fast safe car") # true
palindrome?("Live not on evil") # true
palindrome?("Live free or die hard") # falseWrite a method that check if elements of an array are all Fixnum.
array_of_fixnums?([1, 2, 3]) # return true
array_of_fixnums?(["a", "b", "c"]) # return false
array_of_fixnums?([]) # return trueGiven an array, return a new array consisting of non duplicate elements from the input array.
non_duplicate_values([1, 2, 2, 3, 3, 4, 5]) # return [1, 4, 5]
non_duplicate_values([1, 2, 2, 3, 4, 4]) # return [1, 3]Given that we have a menu stored as a hash, write a method that can return the cost of an order as in these examples below:
# This menu shows the name of the itmes and their respective price
menu = { rice: 2, chicken: 4, meat: 5 }
ordered_items = { rice: 1, chicken: 1 }
get_order_cost(menu, ordered_items)
# return 6
ordered_items = { rice: 1, meat: 1 }
get_order_cost(menu, ordered_items)
# return 7
ordered_items = { rice: 1, chicken: 2, meat: 2 }
get_order_cost(menu, ordered_items)
# return 20
Just as previous exercise, only this time our method can count the cost of more than one order.
# This menu shows the name of the itmes and their respective price
menu = { rice: 2, chicken: 4, meat: 5 }
get_total_cost(menu, { rice: 1, chicken: 2, meat: 2 })
# return 20
get_total_cost(menu, { rice: 1, chicken: 1 }, { rice: 1, meat: 1 })
# return 139 is a Kaprekar number because 9 ** 2 = 81 and 8 + 1 = 9. Write a method called "kaprekar". When given an integer, this method will return true if the given integer is a Kaprekar number and will return false otherwise.
# 297 is also Kaprekar number since
# 297 ** 2 = 88209 and 88 + 209 = 297
kaprekar(9) # return true
kaprekar(46) # return false
kaprekar(55) # return true
kaprekar(90) # return false
kaprekar(297) # return true
kaprekar(703) # return trueWrite a method called "roman_numeral". When given an integer (up to 1000), this method will Roman numeral version of the integer.
roman_numeral(1) # return I
roman_numeral(2) # return II
roman_numeral(9) # return IX
roman_numeral(26) # return XXVI
roman_numeral(141) # return CXLIWrite a method called "num_to_words". When given an integer (up to 1,000,000), this method will return words version of the integer in Bahasa Indonesia.
num_to_words(0) # return "nol"
num_to_words(1) # return "satu"
num_to_words(10) # return "sepuluh"
num_to_words(11) # return "sebelas"
num_to_words(45) # return "empat puluh lima"
num_to_words(123) # return "seratus dua puluh tiga"
num_to_words(123400) # return "seratus dua puluh tiga ribu empat ratus"