Malware Analysis

Your company is analyzing malware software which targets numerical record files.

The malware checks the value of each record and the values of some of its neighbors. The record is replaced by 0 when it is smaller or equal to either of those neighbors.

For each number, it matches the following pattern, where position 'X', is compared to positions 'T':

T, _, _, X, _, _, _, T

Positions '_' represent neighbors that are ignored. Positions further beyond the 'T's, to the far left or far right, are also ignored.

If the 'X' position is near the left or right border and has no 'T' position neighbor, only one side is considered.

The malware finds all the positions first and only then sets them to 0. For example, if the values in a record file are the following:

[19, 2, 0, 87, 1, 40, 80, 77, 77, 77, 77]

The expected values after the malware runs are:

[19, 0, 0, 87, 0, 0, 0, 77, 77, 0, 0]

In this example, number 2 was removed because 40 is the bigger number.

Implement the simulate function so that the malware behavior is replicated for further study.

ECMAScript 7
Loading...
Loading...

Tags

  • JavaScript
  • Arrays
  • Iteration
  • New
  • Public
  • Easy

Information

Difficulty: Easy

Duration: 20 min

Author: Christian Durán Carvajal

Score Distribution

Not enough data for chart.

Would you like to see our other questions?

We have 1000+ premium hand-crafted questions for 160+ job skills and 20+ coding languages. We prefer questions with small samples of actual work over academic problems or brain teasers.

Would you like to see our tests?

The following tests contain JavaScript related questions:

On the blog

Since we're all biased and we use incorrect proxies, why not just outsource hiring to experts or recruitment agencies? After all, they've been screening people for many years, so they must know how to do it right?

Not really. I was surprised to discover that many experts...