Light Mode
Dark Mode
Some problems with tests

Local test are running correct and complete, but server returns error after clicking 'check': Can someone help me to fix this problem?

'use strict';

function mostWanted (data) {
    let result = {};
    let splittedData = data.split('');
    let lowerCaseData = splittedData.map(letter => letter.toLowerCase());
    let withNoPunctuations = lowerCaseData.filter(letter => !/[^\w+]/.test(letter));
    withNoPunctuations.forEach((item) => {
        if (item in result) {
            result[item] += 1;
        } else result[item] = 1;
    });
    let entries = Object.entries(result).sort(function (x1, x2) {
        if (x1[1] > x2[1]) return -1;
        if (x1[1] < x2[1]) return 1;
        if (x1[0] < x2[0]) return -1;
        return 0;
    });
    if (entries.length > 0) {
        return entries[0][0];
    } else {
        return '';
    }
}

var assert = require('assert');
if (!global.is_checking) {
    assert.equal(mostWanted("Hello World!"), "l", "1st example");
    assert.equal(mostWanted("How do you do?"), "o", "2nd example");
    assert.equal(mostWanted("One"), "e", "3rd example");
    assert.equal(mostWanted("Oops!"), "o", "4th example");
    assert.equal(mostWanted("AAaooo!!!!"), "a", "Letters");
    console.log("Coding complete? Click 'Check' to review your tests and earn cool rewards!");
}
Attachment
  • task.most-wanted-letter
Created: Feb. 12, 2020, 11:48 a.m.
Updated: Feb. 13, 2020, 9:42 a.m.
0
11
User avatar
alexerisov