Integrity Check



In order to ensure the integrity of a message transmitted to our system through communication channels prone to noise and errors, we re-transmit the message six times for every 6 digits (numbers).

In our example, the source wants to send the number 521375 to our system. The message is transmitted 6 times and each value received is appended to the retransmission variable.

For certain retransmitted data, you will notice that certain numbers have mutated during transmission, e.g. the 2nd entry of the retransmissions array has a 9 at the third position (where is should be a 1).

In order to recreate the original (source) data from the retransmitted values, we need to check each digit from each transmission, and keep the most frequent number as the best candidate. for example the first digit in the 6 retransmitted values is 5 for the first 5 values and 7 for the last one. Since the most frequent number is 5, we keep it as the best candidate for the first digit of our value and then move on to the other digits.

After checking each digit, you should be able to get the original number (521375) as the final value.

In this exercise, you will need to create the code that checks the values found in the retransmissions array and reconstructs the original message.

The idea is to create a function that finds the most frequent number in a list of numbers and then use that function to check all the digits of each retransmitted value.

const correctData = 521375;
const retransmissions = [
function getSourceFromRetransmission( data ){
  // Your code here...
// You must ensure that the following assertion does not fail:
console.assert( getSourceFromRetransmission( retransmissions ) === 521375, "Failed to reconstruct the original data!" );