Skip to content

Commit da2dced

Browse files
committed
add dominant writing direction
1 parent 435410e commit da2dced

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

chapter_five.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function everyWithSome(array, test) {
3939

4040
console.log(everyWithSome([2, 4, 16], n => n < 10));
4141

42-
//dominant writing direction --- characterscript and countBy functions taken from the book
42+
//dominant writing direction --- characterScript and countBy functions taken from the book
4343

4444
function characterScript(code) {
4545
for (let script of SCRIPTS) {
@@ -58,7 +58,7 @@ function countBy(items, groupName) {
5858
let name = groupName(item);
5959
let known = counts.findIndex(c => c.name == name);
6060
if (known == -1) {
61-
counts.push({name, count: 1});
61+
counts.push({ name, count: 1 });
6262
} else {
6363
counts[known].count++;
6464
}
@@ -73,9 +73,8 @@ function dominantDirection(text) {
7373
return script ? script.direction : 'none';
7474
})
7575

76-
return grouping;
77-
76+
return grouping.reduce((a, b) => a.count > b.count ? a.name : b.name);
7877
}
7978

80-
8179
console.log(dominantDirection("Hello!"));
80+
console.log(dominantDirection("Hey, مساء الخير"));

0 commit comments

Comments
 (0)