First of all I would like to apologize for the delay. It took me ~3 hours instead of 2, because I was interrupted several times, first time by unexpected call of a head hunter, just when I've started and then by my kids.
I chose TypeScript because I was a bit mistaken in the first place, for your initial google form says that we can choose any language of our choice and a second one precises that it should be Scala if possible. It was too late to change when I've started. I expected to have an exercise with a web based editor, kind of codility.com. If you ever tried their Scala editor you will understand why people choosing javascript for solving their tasks.
If you have any doubt about my ability to write Scala, you can check one of my earlier topics.
In the true life I would never submit something without writing unit tests when it's suitable. The task of this exercise can go far, so in normal circumstances I would strongly recommend to use unit tests.
I've used an imaginary super entity to describe estate properties that I've called IEstateProperty
but I would strongly recommend to split it into more specific types of properties, like flat, terrain, house, castle, boat, etc.
We have a properties set of size K and we have a buyers set of size M, for each new Mn entry we need find and alert an appropriate sub set of K(0..i) elements.
I've used functional composition to describe and assemble criteria matchers. I've leveraged a railway oriented programming approach in order to not interrupt the composed chain of matchers.
In order to go faster I've used a discriminated union of type Boolean|IAlertProfile
, which according my opinion can be made in far better way.
The complexity of my solution is linear of order O(n)
in the case when we need to notify buyer by incoming properties publications. In case when we need to remind all buyers about all potential matches the complexity will increase to O(nm)
.
Thanks for interesting challenge, hope my work meet your expectations.