function every(array, test) {
    for (var i = 0; i < array.length; ++i) {
        if (!test(array[i]))
            return false;
    }
    return true;
}

function some(array, test) {
    for (var i = 0; i < array.length; ++i) {
        if (test(array[i]))
            return true;
    }
    return false;
}

function dominantDirection(text) {
    let scripts = countBy(text, char => {
        let script = characterScript(char.codePointAt(0));
        return script ? script.direction : "none";
    }).filter(({name}) => name != "none");

    return scripts.reduce((a, b) => a.count > b.count ? a : b).name;
}

Add Chapter 05, exercise 4
Add Chapter 05, exercise 4
