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

    if (counted.length == 0) return "ltr";

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

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

Add chapter 5, exercise 4
Add chapter 5, exercise 4
