• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Bear Bibeault
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Jj Roberts

How can I modify the code to an exercise to pass the tests?

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could anyone help me with the following exercise:

From https://tiko.jamk.fi/~tuito/tira/dst2mapit.txt you can see three Map data structures of shops: the name of the shop and prices of the shop. Make three functions that returns the following map: Map { 'ykauppa' => 26 }. The key is the name of the shop that sum of the items is the smallest, so we are looking the cheapest shop.

I have been given the following hints: 1) sum(shop) returns the sum of prices of the items in a shop (map.values()). 2) createSumMap(key, ...shops) creates and returns a new map that key-value pairs contains shops and the sum of items.

3) minValueMap(mapX) -function creates the map from previous map. One can use for example forEach.

I was given the following test file:


My effort was

But this returns an error:

What is my mistake? Do I have to implement also the function get? I thought that it is enough is the function returns a suitable map.
 
Marshal
Posts: 3264
487
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Jaakko Seppälä wrote:
But this returns an error:

What is my mistake? Do I have to implement also the function get? I thought that it is enough is the function returns a suitable map.


It looks like your function is returning a number, not a map.
 
Morning came much too soon and it brought along a friend named Margarita Hangover, and a tiny ad.
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic