:::: MENU ::::

Ruby JOB Interview Question – Parsing JSON and displaying movies in ascending order with average rating

I came across one site for javascript conferences where there was one job posting linked to this ruby quiz. I am just novice ruby developer so I tried to solve this job level quiz to check my ruby skills.


You could download (pull) this quiz repository from employer’s github page.
Problem – Parse json file stored in data/movies.json and sort them alphabetically with average rating.

Json File:-

Ruby Implementation:-

  • First of all use json class to parse data with
  • Then create two hash variables. One to store Movies Genres and Other to store Ratings.
  • Our Goal is to print on console like this


  • So, iterate over variable[‘movies’] using each iteration function.
  • Then check for if genre exists for the movie or not?
  • If genre exist just store into genre hash key and rating as value, however if hash key already exist add its rating to previous value. Also, store occurrence of genre into another hash with genre as key and occurrence as value.

  • Now sort genre=>rating hash with ruby sort function
  • Iterate it and display average rating on console to finish up assignment.

So Final Ruby Code would be


My console output is.

So, what do you think ?