exercism / elm-analyzer

GNU Affero General Public License v3.0
1 stars 4 forks source link

Check rule at `top scores` #56

Closed marperia closed 12 months ago

marperia commented 1 year ago

I wrote a function

aggregateScorers : List PlayerName -> Dict PlayerName Int
aggregateScorers playerNames =
    let
        scoredList = List.map (\name -> (name, 0)) playerNames
        playerDict = Dict.fromList scoredList
    in
    List.foldr updateGoalCountForPlayer playerDict playerNames

But I see essential badge

aggregateScorers is most easily written using List.foldl and updateGoalCountForPlayer.

P. S. It's not easy to understand that I should use List.foldr because there is no foldr examples anywhere else!!!

ceddlyburge commented 1 year ago

Hi There, thanks for this.

Just for reference, the example solution has this, which is a bit simpler

aggregateScorers : List PlayerName -> Dict PlayerName Int
aggregateScorers playerNames =
    List.foldl updateGoalCountForPlayer Dict.empty playerNames

I think you could use either List.foldl or List.foldr here though, so we could update the rules to allow for this.

And maybe we should add something to the hints for List.foldl and List.foldr. We don't teach every function of every module, as it would take a long time to develop, and a long time for the student to complete, and probably be a bit boring. The idea is more to give students the basic building blocks, and provide links to the documentation for the more detailed things.

marperia commented 1 year ago

@ceddlyburge my updateGoalCountForPlayer function looks like this

updateGoalCountForPlayer : PlayerName -> Dict PlayerName Int -> Dict PlayerName Int
updateGoalCountForPlayer playerName playerGoalCounts =
    Dict.update playerName (Maybe.map (\x -> x + 1)) playerGoalCounts

and it doesn't pass test with your example. I need pre-generated dictionary to update values because of using Dict.update instead of using this

updateGoalCountForPlayer : PlayerName -> Dict PlayerName Int -> Dict PlayerName Int
updateGoalCountForPlayer playerName playerGoalCounts =
    let
        currentCount =
            Dict.get playerName playerGoalCounts
    in
        case currentCount of
            Just count ->
                Dict.insert playerName (count + 1) playerGoalCounts

            Nothing ->
                Dict.insert playerName 1 playerGoalCounts

But I will be appreciated if you correct me because I'm newbie in Elm.

ceddlyburge commented 1 year ago

Hi There, this sort of question is probably best answered through the mentoring part of exercism. They will be able to see all your code for example, and the discussion bits are probably better suited to it.

Have you asked for a mentor to look at your code?

ceddlyburge commented 1 year ago

@marperia , I can see a solution of yours to Paola's Prestigious Pizza, but nothing for Top Scorers. (Also, the pizza exercise is quite difficult, but it looks like you have completed it ok ...)