i reading through JavaScript Eloquent and came across a code snippet which it doesn't explain how this works
let scripts = countBy(text,char => {
let script = characterScript(char.codePointAt(0))
return script ? script.direction : "none";
}).filter(({name}) => name != "none")
return scripts
}
function countBy(items, groupName) {
let counts = [];
for (let char of text) {
let name = groupName(item);
let known = counts.findIndex(c => c.name == name);
if (known == -1) {
counts.push({name, count: 1});
} else {
counts[known].count++;
}
}
return counts;
}
so this is what i cant get my head around how it works,
.filter(({name}) => name != 'none')
how does this pull the local variable from within a function and can use it to filter by this variable? and why does it have to be between theses ({})
?