Get Students with Names and Top Notes II

Published by Werdna in

Create a function that takes an array of hashes like [{ "name"=>'John', "notes"=>[3, 5, 4]}, { "name"=>"Mich", "notes"=>[1, 3, 5]}] and returns an array of hashes like [{ "name"=>"John", "top_note"=>5 }, {"name"=>"Mich", "top_note"=>5}].

If a student has no notes (an empty array), return top_note=> 0.

Examples

get_name_and_top_note([{ "name"=>"John", "notes"=>[2, 4, 5]}, { "name"=>"Mich", "notes"=>[1, 3, 5]}])  ➞
[{ "name"=>"John", "top_note"=>5 }, {"name"=>"Mich", "top_note"=>5}]

get_name_and_top_note([{ "name"=>"Paul", "notes"=>[]}, {"name"=>"Victoria", "notes"=>[3, 4, 2, 1]}])  ➞ [{ "name"=>"Paul", "top_note"=>0 }, {"name"=>"Victoria", "top_note"=>4}]

Notes

  • Please do not translate this challenge into JavaScript.
  • This challenge is a translation of Bartosz Cytrowski's JavaScript challenge that was not properly translated to Python. You can find the challenge here.
Watch a quick demo on how Edabit works.