fork download
  1. # your code goes here
  2. require 'json'
  3.  
  4.  
  5. def find_applicants(myJson, keyword)
  6. names = []
  7. myJson["jobs"].each do |job|
  8.  
  9. job["applicants"].each do |applicant|
  10. tags = applicant["tags"]
  11. if tags.include? keyword then
  12. names << applicant["name"]
  13. end
  14. end
  15. end
  16. names
  17. end
  18.  
  19. myJson = JSON.parse('{
  20. "jobs": [
  21. {
  22. "id": 1,
  23. "title": "Software Developer",
  24. "applicants": [
  25. {
  26. "id": 1,
  27. "name": "Rich Hickey",
  28. "tags": ["clojure", "java", "immutability", "datomic", "transducers"]
  29. },
  30. {
  31. "id": 2,
  32. "name": "Guido van Rossum",
  33. "tags": ["python", "google", "bdfl", "drop-box"]
  34. }
  35. ]
  36. },
  37. {
  38. "id": 2,
  39. "title": "Software Architect",
  40. "applicants": [
  41. {
  42. "id": 42,
  43. "name": "Rob Pike",
  44. "tags": ["plan-9", "TUPE", "go", "google", "sawzall"]
  45. },
  46. {
  47. "id": 2,
  48. "name": "Guido van Rossum",
  49. "tags": ["python", "google", "bdfl", "drop-box"]
  50. },
  51. {
  52. "id": 1337,
  53. "name": "Jeffrey Dean",
  54. "tags": ["spanner", "BigTable", "MapReduce", "deep learning", "massive clusters"]
  55. }
  56. ]
  57. }
  58. ]
  59. }')
  60.  
  61.  
  62. apps = find_applicants(myJson, 'google')
  63. puts apps
  64.  
  65.  
Success #stdin #stdout 0.02s 8068KB
stdin
Standard input is empty
stdout
Guido van Rossum
Rob Pike
Guido van Rossum