Skip to content

Instantly share code, notes, and snippets.

@chingsley
Created January 7, 2022 23:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chingsley/6d943cc180687679f35a7dbb9a14ad42 to your computer and use it in GitHub Desktop.
Save chingsley/6d943cc180687679f35a7dbb9a14ad42 to your computer and use it in GitHub Desktop.
require 'active_support/all'
@candidates = [
{
id: 5,
years_of_experience: 4,
github_points: 293,
languages: ['C', 'Ruby', 'Python', 'Clojure'],
date_applied: 5.days.ago.to_date,
age: 26
},
{
id: 7,
years_of_experience: 1,
github_points: 145,
languages: ['JavaScript', 'Ruby', 'Go', 'Erlang'],
date_applied: 15.days.ago.to_date,
age: 19
},
{
id: 9,
years_of_experience: 6,
github_points: 435,
languages: ['JavaScript', 'SQL', 'C#'],
date_applied: 1.day.ago.to_date,
age: 32
},
{
id: 10,
years_of_experience: 3,
github_points: 232,
languages: ['Java', 'Ruby', 'JavaScript'],
date_applied: 12.days.ago.to_date,
age: 31
},
{
id: 11,
years_of_experience: 12,
github_points: 32,
languages: ['VB', 'Cobol', 'Fortran'],
date_applied: 2.days.ago.to_date,
age: 42
},
{
id: 13,
years_of_experience: 2,
github_points: 328,
languages: ['Python', 'Ruby', 'JavaScript'],
date_applied: 4.days.ago.to_date,
age: 25
},
{
id: 15,
years_of_experience: 1,
github_points: 400,
languages: ['JavaScript', 'Ruby'],
date_applied: 3.days.ago.to_date,
age: 16
},
]
def find(id)
return @candidates.select { |candidate| candidate[:id] == id }
end
def experienced?(candidate)
return candidate[:years_of_experience] >= 2
end
def has_high_github_points?(candidate)
return candidate[:github_points] >= 100
end
def knows_ruby_or_python?(candidate)
return (candidate[:languages] & ["Ruby", "Python"]).any?
end
def applied_in_last_15_days?(candidate)
return Date.today - candidate[:date_applied] <= 15;
end
def above_18?(candidate)
return candidate[:age] >= 18;
end
def qualified_candidates(candidates)
candidates.select { |c| experienced?(c) && has_high_github_points?(c) && knows_ruby_or_python?(c) && applied_in_last_15_days?(c) && above_18?(c) }
end
def ordered_by_qualifications(candidates)
candidates.sort do |a, b|
[b[:years_of_experience], b[:github_points]] <=> [a[:years_of_experience], a[:github_points]]
end
end
# This is the main entrypoint into the program
# It requires the other files/gems that it needs
require 'pp'
require './candidates'
require './filters'
## Your test code can go here
puts qualified_candidates(@candidates)
puts ordered_by_qualifications(@candidates)
pp @candidates
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment