Developers Club geek daily blog

3 years ago
The Hola company announces competition on programming on JS with a solid prize fund again:

  1. First place: 1500 USD
  2. Second place: 1000 USD
  3. Third place: 500 USD
  4. Perhaps, we will decide to note someone's extremely original solution a special prize in 350 USD.
  5. If you send someone the link to this tender, having put our address in CC, and this person will take a prize, you receive the same sum, as well as it.

We look for talented programmers therefore authors of interesting solutions will be invited to interviews.

Tender on programming on JS: Mail filters


Some of those who remember our previous tenders were dissatisfied that conditions of tasks were formulated indistinctly, and from the participant it was required "to guess" what we meant. This time the condition is formulated extremely unambiguously, and at the disposal of participants — reference implementation of a solution. That whose code will be the fastest on condition of passing of tests for a correctness will win.

Tender conditions in English are posted on our website. Below — transfer into Russian.

  • Send solutions to
  • Decisions are made till December 25, 2015, 11:59:59 PM by UTC.
  • Winners will be declared on January 8, 2015.
  • It is possible to send solutions repeatedly, but from each participant only the latest solution sent before the termination of term of acceptance of works will be considered.
  • For testing we will use Node.js v5.0.0 (stable release at the time of the publication).
  • Your solution has to consist of the only file on JS.
  • The solution has to be on pure JS. If you prefer CoffeeScript or similar languages, it is necessary to ottranslirovat a solution in JS before sending. We welcome (but we do not demand) sending the original together with result of broadcasting (but not instead of).
  • It is impossible to load any modules, even those that are included in the standard package of Node.js.
  • We will test solutions for a correctness and performance. Only the solutions which passed test for a correctness will be allowed to testing for performance. Will win against the fastest of correct solutions.
  • All works of participants, and also our tests for a correctness and performance, will be published when summing up.
  • Summing up the results, we will publish your complete name (or an alias if you subscribe by it), but not the e-mail address.
  • The publication by participants of the solutions before the end of tender is forbidden. Violators will be disqualified.
  • If the statement of the problem seems to you ambiguous, check the understanding of a condition by means of our reference implementation (see below) instead of asking questions about a condition. If you find out that the behavior of reference implementation contradicts a condition, please, tell us.

Problem definition

You develop system of use of filters for mail system. You need to write the module for Node.js exporting one function:

filter(messages, rules)

  • messages — it is the object putting in compliance to unique identifiers of messages objects with two properties: from and to. Each such object describes one e-mail.
  • rules — it is an array of objects with three properties: from (optional), to (optional) and action (surely). Each of these objects describes one rule of filtering.

All line values in input data non-blank also contain only ASCII characters in range from 0x20 to 0x7F inclusive.

It is considered that the letter satisfies to the rule of filtering if both of its properties from and to satisfy to the masks set in the corresponding properties of the rule. Masks are case-sensitive; to the character * in a mask satisfies any number (0 or more) any characters, and to the character ? — one any character. If properties from or to are absent in the rule of filtering, as value it is by default used *. As a result, if both properties are not in the rule from and to, to it satisfy all letters.

It is necessary to apply all rules to which it satisfies to each letter, in the correct order. Function filter has to return the object putting arrays of actions in compliance to message IDs. For each letter such array has to contain values of properties action all rules to which this letter satisfies, as transfer of rules in an array rules. If the letter does not satisfy to any of rules, the empty array for this letter all the same has to be present at result.


Below the common example of correct function call is given filter:

    msg1: {from: '', to: ''},
    msg2: {from: '', to: ''},
    msg3: {from: '', to: ''}
}, [
    {from: '*', action: 'tag work'},
    {from: '*', action: 'tag spam'},
    {from: '', to: '', action: 'folder jack'},
    {to: '', action: 'forward to'}

Correct implementation filter in this case will return the following:

    msg1: ['folder jack', 'forward to'],
    msg2: ['tag spam', 'forward to'],
    msg3: ['tag work']

Reference implementation

We prepared reference implementation of function filter to the address For preset values of arguments it issues correct result. This implementation also strictly checks a correctness of entry values (from your solution of verification of input data it is not required). In disputable cases instead of asking us questions about a statement of the problem, use reference implementation. If you suspect that reference implementation issues failing response for these or those input data, please, tell us.

Not to allow an overload of our server, we limited amounts of input data to 10 rules and 10 letters. Your solution should not have such restrictions.

To reference implementation to the address mentioned above it is possible to do HTTP requests by the POST method with a body of request of type application/json. The body has to represent object with two properties: messages and rules — containing values of the corresponding function arguments filter. The answer body, also in the JSON format, will contain value which function has to return. At inadmissible input data you receive the answer of HTTP 400 with the description of an error in a format text/plain.

We wish good luck to all participants!

This article is a translation of the original post at
If you have any questions regarding the material covered in the article above, please, contact the original author of the post.
If you have any complaints about this article or you want this article to be deleted, please, drop an email here:

We believe that the knowledge, which is available at the most popular Russian IT blog, should be accessed by everyone, even though it is poorly translated.
Shared knowledge makes the world better.
Best wishes.

comments powered by Disqus