You only need to write one function and some unit tests that prove (first and foremost to you) that the function does what you intended. You don't need to do more than that. For example, you don't need to also write all the dependencies, readme, include runtime config and dependency management, pay people on Fivr to generate some fake data, develop an entire web app, put it in a Docker container and deploy it to AWS, incorporate, raise money and make billions from our coding assignment. One function and some tests is all we need.
We use JavaScript, but feel free to use any language you're comfortable with. Please don't use JavaScript just because we use JavaScript. It's actually quite fun to see solutions in different languages. But please don't use a different language just because we said this.
We will pretend we are giving you a few existing dependency functions. We described their interface below. You should use them to write your function. Even though we're not actually giving you real code, tests should allow you to pretend it's there.
Assume you can require the following 3 functions:
fetchDatabaseMapping(userIds : <array of integers>)
, which yields:
[
{
"userId": <integer>,
"databaseId": <integer>
},
...
]
fetchNamesFromDatabase(databaseId : <integer>, userIds : <array of integers>)
, which yields:
[
{
"userId": <integer>,
"name": <string>
},
...
]
fetchReads(userIds : <array of integers>)
, which yields:
[
{
"userId": <integer>,
"reads": <integer>
},
...
]
Write a new function that takes a list of user IDs and yields a list of top 10 users from that list, by number of reads, along with their names. Also write unit tests that verify that your function works.
fetchTop10UsersByReads(userIds: <array of integers>)
, which yields
[
{
"userId": <integer>,
"name": <string>,
"reads": <integer>
},
...
]
Additional context:
- Assume that
fetchDatabaseMapping
,fetchNamesFromDatabase
andfetchReads
functions perform network requests, so they might be slow and error-prone. - Have in mind that the list of user IDs can be very long (e.g., thousands), while the number of user databases is usually low (e.g., less than ten).
- Consider edge cases, like errors or missing data, and decide how to handle them.
When you're done, you can share your solution either on Github or in a ZIP file or any other way you see fit, including a USB stick brought to us by a carrier pigeon. That would be impressive, but is not mandatory.
Thanks and good luck!