jobbet litt med arrow functions
This commit is contained in:
parent
81f3550ab2
commit
98723969eb
|
@ -0,0 +1,20 @@
|
||||||
|
const SCRIPTS = require("./scripts.js");
|
||||||
|
|
||||||
|
function reduce(array, combine, start) {
|
||||||
|
let current = start;
|
||||||
|
for(let element of array){
|
||||||
|
current = combine(current, element);
|
||||||
|
}
|
||||||
|
return current
|
||||||
|
}
|
||||||
|
console.log(reduce([1,2,3,4], (a,b) => a +b, 0));
|
||||||
|
console.log([1,2,3,4].reduce((a,b) => a +b));
|
||||||
|
|
||||||
|
function characterCount(script) {
|
||||||
|
return script.ranges.reduce((count, [from, to]) => {
|
||||||
|
return count + (to - from);
|
||||||
|
}, 0);
|
||||||
|
}
|
||||||
|
console.log(SCRIPTS.reduce((a,b) => {
|
||||||
|
return characterCount(a) < characterCount(b) ? b : a;
|
||||||
|
}));
|
|
@ -0,0 +1,11 @@
|
||||||
|
const SCRIPTS = require("./scripts.js");
|
||||||
|
|
||||||
|
function map(array, transform) {
|
||||||
|
let mapped = [];
|
||||||
|
for (let element of array){
|
||||||
|
mapped.push(transform(element));
|
||||||
|
}
|
||||||
|
return mapped
|
||||||
|
}
|
||||||
|
let rtlScripts = SCRIPTS.filter(s => s.direction == 'rtl');
|
||||||
|
console.log(map(rtlScripts, s => s.name));
|
Loading…
Reference in a new issue