Jump to content

Unique characters in each string: Difference between revisions

m
Line 461:
 
return sort([
...foldrws.slice(1).reduceRight(
(a, x) => compose(intersect, charSet(x)(
) charSet(a)
charSet(ws[0]),
)charSet(ws[0])
ws.slice(1)
)]
.filter(c => wordCount === charFreqs[c])
.filter(c => wordCount === charFreqs[c])
).join("");
})() : "";
Line 494 ⟶ 493:
}
), {}
);
 
 
// compose (<<<) :: (b -> c) -> (a -> b) -> a -> c
const compose = (...fs) =>
// A function defined by the right-to-left
// composition of all the functions in fs.
fs.reduce(
(f, g) => x => f(g(x)),
x => x
);
 
 
// foldr :: (a -> b -> b) -> b -> [a] -> b
const foldr = f =>
// Note that that the signature of foldr differs
// from that of foldl - the positions of
// current value and accumulator in f are reversed
acc => xs => [...xs].reduceRight(
(a, x) => f(x)(a),
acc
);
 
9,655

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.