function scoreBy(fn, list) {
const scores = R.map(fn, list);
const zipped = R.zip(scores, list);
const scored = R.sortBy(R.head, zipped);
return R.last(R.last(scored));
}
R.useWith(R.reduce, R.maxBy)
. http:// bit.ly/1KnFLGv
I'm trying to do something without writing the keyword function
(i.e. creating the function using R.*
as an exercise). The goal is a function that takes two arguments, the first is a list of ids, the second is a list of objects (with an id
property). The function should return the items from the second list that have ids from the first list. Here is a small working example (with one use of function
):
var a = [ 1, 2, 3 ];
var b = [ {id: 1, b: 'Yay!' }, { id: 3, b: 'Oh yeah!' }, { id: 4, b: 'Oh noes!' } ];
var answerFunc = function (x, y) { R.pipe(R.map(R.pipe(R.unary(R.propEq('id')), R.partialRight(R.find, y))), R.filter(R.identity))(x) };
answerFunc(a, b);
// -> [ { id: 1, b: 'Yay!' }, { id: 3, b: 'Oh yeah!' } ]
I can't figure out how to "extract" the y
parameter from the middle so I can say something like:
var answerFunc = R....
Any ideas?
a
into R.flip(R.contains)
without affecting the composition with R.prop('id')
. So now I'm calling R.always(R.prop('id'))
with null
.
Basically:converge(f, a, b)(x, y) === f(a(x, y), b(x, y))
useWith(f, a, b)(x, y) === f(a(x), b(y))
So the passed in variable makes its way "deeper" into "the middle".