I don’t see any exercises with Records in the track, which is specific to PureScript. Don’t we want to take some from Functions and Records - PureScript by Example, (MIT Licence)?
I’m not an expert, but I can give it a try.
I don’t see any exercises with Records in the track, which is specific to PureScript. Don’t we want to take some from Functions and Records - PureScript by Example, (MIT Licence)?
I’m not an expert, but I can give it a try.
Something like this:
Introduction
You’ve recently volunteered to help organize a neighborhood directory. Each entry has a name and address, but over time, duplicate entries have crept in. You quickly notice that some names appear multiple times with slightly different addresses—like “John Doe” listed on both Elm Street and Pine Street. To keep things tidy, you decide to clean up the directory by removing these duplicates.
Since this is a small community, duplicates are defined by matching first and last names, regardless of address. Your task is to identify and keep only the first instance of each unique name.
Instructions
Your goal is to write a function, removeDuplicates, that will remove duplicate entries from an address book. Two entries are considered duplicates if they have the same firstName and lastName, even if their address fields are different.
Here are the types you’ll work with:
type Entry =
{ firstName :: String
, lastName :: String
, address :: Address
}
type Address =
{ street :: String
, city :: String
, state :: String
}
type AddressBook = List Entry
Example
Suppose you start with the following address book:
addressBook =
[ { firstName: “John”, lastName: “Doe”, address: { street: “123 Elm St”, city: “Springfield”, state: “IL” } }
, { firstName: “Jane”, lastName: “Smith”, address: { street: “456 Oak St”, city: “Springfield”, state: “IL” } }
, { firstName: “John”, lastName: “Doe”, address: { street: “789 Pine St”, city: “Springfield”, state: “IL” } }
]
After applying removeDuplicates addressBook, you should get:
[ { firstName: “John”, lastName: “Doe”, address: { street: “123 Elm St”, city: “Springfield”, state: “IL” } }
, { firstName: “Jane”, lastName: “Smith”, address: { street: “456 Oak St”, city: “Springfield”, state: “IL” } }
]
In this case, only the first “John Doe” entry is kept, and any additional entries with the same name are removed.
@shmygol Please add codeblock markup around your code. Thank you!
Currently there are no maintainers assigned for Purescript. @BNAndras last added something. Maybe they or @iHiD know someone to ping?
I don’t know PureScript. @kahgoh added the knapsack exercise to the track earlier this year so they might be helpful here.
I think I’ll just make a PR.
It seems records are loosely like a named tuple with keys and values. Would it be simpler to adapt an existing practice exercise from problem-specifications? I’m ambivalent about adding a practice exercise from scratch since that’s not a small task to get right.
The track only has 30 some exercises implemented so we should have a lot of potential exercises that might lend themselves to inputs or returned values using records.
Ok, I’ll check other tracks.