interview questions
# remove duplicates and nil
array = [1, 1, 2, 3, nil]
array_duplicate = array.compact
array_nil = array.reject? {|c| c.empty}
# find items matching string "Si"
array = ['Simple', 'Ample', 'Sit']
def check_array
if array
end
# find users where the score is more than 100
array = [
{ name: 'Dan', score: 110 },
{ name: 'Mike', score: 57 },
{ name: 'Jill', score: 120 }
]
#sum of values
hash = {"a"=>10, "b"=>20, "c"=>30}
hash1 = hash.merge(hash[0]).merge([]hash1]).merge([hash[2])
sum_of_values = hash1.inject[sum+]
# find common items from below arrays
array1 = [1, 2, 3 ]
array2 = [0, 5, 2]
print array3 = array1 & array2
# use below methods with proper arguments
def func1(*input)
puts input
end
def func2(**input)
puts input
end
# for example
def math(x, y)
end
math(2,3)
# use metaprogramming to refactor these methods
def admin?
role == 'admin'
end
def marketer?
role == 'marketer'
end
def sales?
role == 'sales'
end
# write url routes for comments and bulk_upload
resources :posts do
member do
get 'comments'
end
collection do
post 'bulk_upload'
end
end
# give example of has_many through association
class Physician
belongs_to :patients,through: :appointments
has_many :appointments
end
class Appointment
belongs_to :physician
belongs_to :patient
end
class Patient
belongs_to :physicians,through: :appointments
has_many :appointments
end
# ajax call to list post comments with controller, view, js code
# write rspec. if poduct count is 0 display message "Out of stock"
Comments
Post a Comment