5

I've made this snippet using ramda to check if any value of array A exists in array B, assuming they are flat arrays.

var hasAtLeastOneTruthValue = ramda.contains(true);
var alpha = [1,2,3]
var beta = [4,1,7];

var valueOfArrayInArray = ramda.map(function(a_v){
    return ramda.contains(a_v, beta);
});

console.log(hasAtLeastOneTruthValue(valueOfArrayInArray(alpha)));

What I do not like is that hardcoded beta inside valueOfArrayInArray. Can it be done differently so that it's not? Please note that I'm not looking for a completely different implementation that has the same effect, but simply to understand currying better in this case.

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
rollingBalls
  • 1,808
  • 1
  • 14
  • 25

2 Answers2

6

You could partially apply contains from the right:

var valueOfArrayInArray = R.map(R.rPartial(R.contains, beta))

Or flip it:

var valueOfArrayInArray = R.map(R.flip(R.contains)(beta))
elclanrs
  • 92,861
  • 21
  • 134
  • 171
0

Use binding:

var hasAtLeastOneTruthValue = ramda.contains(true);

var alpha = [1,2,3]
var beta = [4,1,7];

function finder(lookup,a_v){
    return ramda.contains(a_v, lookup);
}

var valueOfArrayInArray = ramda.map(finder.bind(null,beta));

console.log(hasAtLeastOneTruthValue(valueOfArrayInArray(alpha)));
  • Thank you for answering! This is a working solution but @elclanrs 's is more "functional" which is what I am trying to get fluent at, so I'm accepting his. – rollingBalls Sep 24 '14 at 19:29